What is our go-to command for manipulating users?
useradd
What does the useradd command do?
It adds a new user.
What is the synopsis of the useradd command when we man it?
useradd [OPTIONS] LOGIN
What do we need in order to add a user using the useradd command?
We need to have administrator rights.
What is the most basic real-world example of using the useradd command, and what do we get asked for when we execute it?
sudo useradd jdoe2. Our password.
What flag do we use with useradd to specify a comment?
The -c flag.
What do most distros store in the comment for a given user?
The full name of the user.
What is the most basic real-world example of creating a user and give them a comment using the useradd command?
sudo useradd -c "Jane Smith" jsmith
How do you set an expiration date for a user when creating it with the useradd command?
By using the -e flag.
eg.
sudo useradd -e 2019/12/31 jsmith
What is the format accepted by the -e flag when using the useradd command?
YYYY/MM/DD
eg. 2019/12/31
How do you set the default shell for a user when creating it with the useradd command?
By using the -s flag and giving it the path to the binary for that particular shell.
eg.
sudo useradd -s /bin/zsh jsmith
What is the path to the default home directory for a given user?
/home/[username]
eg.
If the username is “jsmith”, the home directory would be home/jsmith.
How do we specify a non-default home directory for a given user when creating it using the useradd command?
By using the -d flag.
eg.
sudo useradd -d /home/johnsmith jsmith
When we’re using the useradd command to create a new user with a non-default home directory, what is the secondary step that we must undertake and why?
useradd command, the home directory we specified will not be created.How do you print the ID of a user on the terminal?
By using the id command and giving it the username that we want to get the ID for.
eg.
sudo id sarah
How do you delete a user using the terminal?
By using the userdel command and giving it the username of the user we’d like to delete.
eg.
sudo userdel sarah
How do you specify that the home directory of the given user should be deleted when using the userdel command?
By using the -r flag.
eg.
sudo userdel -r sarah
What does the usermod command do?
It modifies a user account.
How do you modify a user account?
By using the usermod command.
eg.
sudo usermod -c "Not Sarah" sarah
How do you change the username of an account using the usermod command?
By using the -l flag.
eg.
sudo usermod -l sjones sarah
...will change the username from `sarah` to `sjones`.
What is the default password for users that are added using the useradd command, and what does this mean?
useradd command.How can you attach a password to a user that was created by the useradd command?
By using the passwd command.
eg.
sudo passwd sjones
...will prompt us for a new password for the user `sjones`
How do you set an expiration date for a user’s password?
eg. so that they have to change it before a certain date after they’ve started to use their account.
By using the chage command.
What does the chage command do?
It changes the number of days between password changes and the date of the last password change. This information is used by the system to determine whether a user must change his/her password.