Linux User Management
User management includes everything from creating a user to deleting a user on your system. User management can be done in three ways on a Linux system.
Graphical tools are easy and suitable for new users, as it makes sure you'll not run into any trouble.
Command line tools includes commands like useradd, userdel, passwd, etc. These are mostly used by the server administrators.
Third and very rare tool is to edit the local configuration files directly using vi.
The local user database in Linux is /etc/passwd directory.
Look at the above snapshot, it has seven columns separated by a colon. Starting from the left columns denotes username, an x, user id, primary group id, a description, name of home directory and a login shell.
The root user is the superuser and have all the powers for creating a user, deleting a user and can even login with the other user's account. The root user always has userid 0.
With useradd commands you can add a user.
Look at the above snapshot, we have created a user xyz along with creating a home directory (-m), setting the name of home directory (-d), and a description (-c).
The 'xyz' received userid as 1004 and primary group id as 1004.
File /etc/default/useradd contains some user default options. The command useradd -D can be used to display this file.
To delete a user account userdel command is used.
Look at the above snapshot, first we have shown the xyz user account with 'tail' command. To delete it, command "userdel -r xyz" is passed.
To recheck, again 'tail' command is passed and as you can see no xyz user account is displayed.
Hence, it is deleted.
The command usermod is used to modify the properties of an existing user.
Look at the above snapshot, user name john is replaced by the new user name jhonny
The /etc/skel/ contains some hidden files which have profile settings and default values for applications. Hence, it serves as a default home directory and user profile. While using useradd -m option, the /etc/skel/ is copied to the newly created directory.
Look at the above snapshot, files of /etc/skel/ is listed.
Deleting Home Directories
By using userdel -r option, you can delete home directory along with user account.
Look at the above snapshot, both home directory as well as user account john is deleted.
The /etc/passwd file also tells about the login shell for the user.
Look at the above snapshot, user guest will log in with /bin/bash shell and user jtp will log in with /bin/ksh shell.
You can change the shell mode with usermod command for a user.
Look at the above snapshot, shell of jtp is changed to /bin/bash from /bin/ksh.
Users can change their login shell with chsh command.
Both the command chsh and chsh -s will work to change the shell.
Look at the above snapshot, command chsh has changed the sssit login shell from /bin/sh to /bin/bash.
Look at the above snapshot, login shell is changed into /bin/s.