UltratechHost Webmaster Forum
RedHat Guide to “useradd” Command in Linux [Part 3] - Printable Version

+- UltratechHost Webmaster Forum (http://forums.ultratechhost.com)
+-- Forum: Tutorials (http://forums.ultratechhost.com/Forum-Tutorials)
+--- Forum: Linux Tutorial (http://forums.ultratechhost.com/Forum-Linux-Tutorial)
+---- Forum: RedHat/CentOS (http://forums.ultratechhost.com/Forum-RedHat-CentOS)
+---- Thread: RedHat Guide to “useradd” Command in Linux [Part 3] (/Thread-RedHat-Guide-to-%E2%80%9Cuseradd%E2%80%9D-Command-in-Linux-Part-3)

Guide to “useradd” Command in Linux [Part 3] - UltratechHost - 09-01-2014


This thread is about special case for useradd command

Previous Posts:

Add a User with Specific Home Directory, Default Shell and Custom Comment

The following command will create a user ‘santa‘ with home directory ‘/var/www/santa‘, default shell /bin/bash and adds extra information about user.

# useradd -m -d /var/www/santa -s /bin/bash -c "Santa Banta" -U santa

In the above command ‘-m -d‘ option creates a user with specified home directory and the ‘-s‘ option set the user’s default shell i.e. /bin/bash. The ‘-c‘ option adds the extra information about user and ‘-U‘ argument create/adds a group with the same name as the user.

Add a User with Home Directory, Custom Shell, Custom Comment and UID/GID

The command is very similar to above, but here we defining shell as ‘/bin/zsh‘ and custom UID and GID to a user ‘raj‘. Where ‘-u‘ defines new user’s UID (i.e. 1000) and whereas ‘-g‘ defines GID (i.e. 1000).

# useradd -m -d /var/www/raj -s /bin/zsh -c "Raj" -u 1000 -g 1000 raj

Add a User with Home Directory, No Shell, Custom Comment and User ID

The following command is very much similar to above two commands, the only difference is here, that we disabling login shell to a user called ‘nat‘ with custom User ID (i.e. 1019).

Here ‘-s‘ option adds the default shell /bin/bash, but in this case we set login to ‘/usr/sbin/nologin‘. That means user ‘nat‘ will not able to login into the system.

# useradd -m -d /var/www/nat -s /usr/sbin/nologin -c "Natwarlal" -u 1019 nat