This is an old revision of the document!
Table of Contents
Usermanagement
To set up a user on a Linux server, there are a few steps you will need to follow. Here is a general guide for doing so:
1. Open a terminal session on the server. Connect to a Server via SSH
2. Run the command sudo adduser <username> to create a new user. You will be prompted to enter a password and other information such as the full name and email address.
3. Once the user has been created, run the command sudo usermod -aG sudo <username> to give the user sudo privileges. This allows the user to run commands as the root user.
4. Run the command su - <username> to log in as the new user.
5. The new user is now set up and can run commands on the server.
Note: This is a general guide and the exact steps may vary depending on the Linux distribution and server configuration. It is recommended to read the documentation of the distribution and tools being used to ensure that the user setup is performed correctly.
Commands
Here are more details on the commands used above, to give you more options on the different steps and more freedome in the way of you configuration.
adduser
The adduser command has a number of options that you can use to specify additional information or behavior when creating a new user. Here is a list of some of the most commonly used options:
all options need a double dash in front of them
system: This option specifies that the user being created is a system user, which means that the user will not be able to log in to the system.
shell: This option allows you to specify the shell that will be used as the default for the new user. By default, the/bin/bashshell is used, but you can specify a different shell if desired.
home: This option allows you to specify the home directory for the new user. By default, the home directory will be/home/<username>, but you can specify a different location if desired.
expiredate: This option allows you to specify an expiration date for the user's account. Once the specified date is reached, the user will no longer be able to log in to the system.
disabled-password: This option allows you to create a user account with a disabled password. This can be useful if you want to create a user account that can be used for certain tasks, but that cannot be used to log in to the system.
These are just a few examples of the options that are available with the adduser command.
For a complete list of options, you can run the man adduser command to get man page for a full documentation
usermod
The usermod command is used to modify user accounts in Linux. It is typically used to change user account attributes, such as the user's login name, password, or group membership. Here is an overview of some of the most useful options for the usermod command, along with their syntax:
-l, –login NEW_LOGIN: This option allows you to change the user's login name. The syntax for using this option is: usermod -l NEW_LOGIN OLD_LOGIN *-p, –password PASSWORD: This option allows you to set or change the user's password. The password should be provided in an encrypted format. The syntax for using this option is: usermod -p ENCRYPTED_PASSWORD USERNAME
-u, –uid UID: This option allows you to change the user's UID (user ID). The syntax for using this option is: usermod -u UID USERNAME *-g, –gid GROUP: This option allows you to change the user's primary group. The group can be specified by name or by GID (group ID). The syntax for using this option is: usermod -g GROUP USERNAME
-G, –groups GROUP_LIST: This option allows you to specify a list of supplementary groups that the user should belong to. The groups can be specified by name or by GID. The syntax for using this option is: usermod -G GROUP_LIST USERNAME *-d, –home HOME_DIR: This option allows you to change the user's home directory. The syntax for using this option is: usermod -d HOME_DIR USERNAME
-m, –move-home: This option allows you to move the user's home directory to the new location specified with the -d option. The syntax for using this option is'': usermod -d NEW_HOME_DIR -m USERNAME
I hope this information is helpful! Let me know if you have any questions or need further clarification on any of the options.