useradd / usermod
Most full-featured modern Linux distributions have graphical ways of managing users. And you certainly won't need to manage any users on the McKelvey Cluster. But it's worth having here as a reference.
useradd
Ā
useradd
Ā useradd
creates a user. You can customize certain things. The -m
flag creates a home directory. You can update what a default home directory looks like in the folder /etc/skel
. For instance if you want all new users to have a Downloads folder, a Documents folder, and a Coding folder. You can use mkdir /etc/skel/{Downloads,Documents,Coding
} to create the directories, then useradd -m newuser
.
You can use man useradd
to see all of the options.
Flag | Effect | Example |
---|---|---|
-p | Set a password | useradd -p $TR0ngP@$$w0r6 newuser |
-G | Set additional groups (especially useful for giving sudo privileges). Multiple groups can be separated by comma | useradd -G wheel,docker -p password newuser |
-s | Set a default shell besides Bash. For instance, some like zsh | useradd -s /bin/zsh -G wheel -p pass newuser |
-m | Creates a home directory | useradd -m -s /bin/zsh -G wheel -p pass newuser |
usermod
Ā
usermod
Ā functions almost identically to useradd
Ā but it changes settings on already existing users. So if you want to change your shell from bash to zsh, you can use usermod -s /bin/zsh myuser
.
One thing that is important to keep in mind is that any attribute you set will completely overwrite the previously existing attribute. For instance, if myuser
Ā is in the wheel
group giving them sudo
Ā privileges, and you want to add them to the docker
Ā group because you are starting to use docker
, you might run usermod -G docker myuser
. The problem with this is that myuser
will be removed from the wheel
Ā group and added to the docker
Ā group removing their sudo
Ā privileges. The way to avoid this is to use the -a
Ā flag to "append" the new attribute to the old one. For example usermod -a -G docker myuser
Ā will just add myuser
to the docker
group and not remove them from anything.