`
If you find these tutorials useful, Please consider making a donation.

TheFrugalComputerLinuxLogo.png
TheFrugalComputerGuy.png
Linux Command Line 6
User Accounts







Linux Command Line (14) Adding New Users pt1

To add a new user to a Linux operating system you must be signed in as a privileged user.

One way to add a new user on an Ubuntu based Linux operating system is type type "sudo adduser" and then the new user name. To add the user testadduser you would type "sudo adduser testadduser" When using the adduser command, you will be prompted to add in the Full Name, Room Number, Work Phone, Home Phone, and Other. You can add this information in or just press enter to leave it blank. When the new user is added this way, a home directory is also added fr that new user.


When adding in a user with "sudo useradd" no home directory is created and a password is not created for the new user.

To add a new user with the useradd command with a home directory we would add the "-m" option (the "m" is for hoMe, "h" is reserved for help) so the command I used was "sudo useradd -m " followed by the user I wanted to add making it "sudo useradd -m testuseraddm"

New users are added to the /etc/passwd file. The passwd file has information about the user, but not the password – the encrypted password is stored in the /etc/shadow file discussed in Adding Users pt2.





 






Linux Command Line (15) Adding New Users pt2

The encrypted passwords are stored in the file /etc/shadow and you must be signed in as a privileged user to view this file.

The /etc/shadow file has the userID and password information as well as fields shwoning when the password was last changed, as well as other information about the password, including when the password will expire and if and when the account will expire.

Even if the user account does not have a password we can still log into that user account using the "su" command, but we must be a privileged user. We switch to the testuseraddm user account with "sudo su testuseraddm" command and then the "exit" command to return back as the user we logged in as.

Privilged users can update a password for a user ID with the "passwd" command followed by that userid they want to change

Any Linux user update their own password themselves by typing "passwd" by itself





 






Linux Command Line (16) Editing Users pt1

We can edit the values in the /etc/shadow file with the chage command.

Using the chage command withe -l option lists out the values from the /etc/shadow file in an easy to read format. The chage command is also used to udpate values on the /etc/shadow file.

The other file we used when adding users was the /etc/passwd file.

We use the getent command to view a single user record off the /etc/passwd file.

We then look at the usermod command to update the user records on the /etc/passwd file as well as records on the /etc/shadow file.

How to change the user shell and user home directory is also shown in this video.





 






Linux Command Line (17) Editing Users pt2

We point the home directory to a new location and we move the home directory to the new location all in the same command.

We also change the user login name with the usermod command and login with the new login name. We see the UID (userID) and GID (group id) are the same as the old login name and that things all work because they are based more on the UID and GID than the login name.





 






Linux Command Line (18) Editing Users pt3

We start by editing the comment for a userID with the usermod command.

We then look at the passwd file and compare the comment just added with the comment added for a user that were created when we added the user and we see the new comment formatting is missing commas and the userID name, office information, and phone number information.

The finger command is installed and then used by typing finger and the userID. The finger command shows the userID comment information nicely formatted.

We then look at the chfn (change finger) command to update the userID comment information for the userID name, office information, and phone numbers

We also look at forcing a userID to update their password on their next login with:
passwd --expire userID
or
sudo chage --lastday 1970-01-01 userID
or
Sudo chage --lastday 0 userID





 






Linux Command Line (19) Disable/Remove UserIDs

We review how an account is locked with a password expire date or if the password has expired and the inactive number of days have passed.

There is also a way to lock the account by setting the account locked with usermod -L userID or passwd -l userID

The status of a user account can be checked by typing sudo passwd -S userID

The account can be unlocked with usermod -U userID or passwd -u userID

To make the user account unusable change the users shell can be set to bin nologin
Another common shell setting to make the account usuable is to set the shell to bin false

To Disable the password aging you use chage -l -1 -m 0 -M 99999 -E -1 userID

Chage userID (will put you in interactive mode to update the chage details)

To delete a userID and keep the home directory files we can type sudo deluser userID
To delete a userID and also remove the home directory we can type sudo --remove-home deluser userID