Add system user linux

15+ adduser command examples in Linux [Cheat Sheet]

adduser is a command-line utility to create a new user in the Linux system. It is a friendlier frontend to the low-level tool ‘useradd’. When adding a new user, it also creates the user directory under the /home directory.

How adduser command works

The default configuration file for adduser is /etc/adduser.conf. adduser command will work according to the default value specified in adduser.conf file.

adduser command adds the details of the new user to the following files.

  • /etc/passwd — It stores user account information.
  • /etc/shadow — It contains the password information of users. The passwords are stored in an encrypted format.
  • /etc/group — It stores group information.

Different examples to use adduser command

You can use adduser command to add a normal user, system user, or user group in the Linux system. Only users with root privileges can add a user to the system. So, you will need to log in as a root user or use sudo to execute adduser command.

The general syntax of adduser command is:

Now, let’s see some practical examples of adduser command to add a user or group in the Linux system.

1. adduser command to add a new user

With this command, you can add a new user to the system. When adding a new user, you will be asked to enter some information.

Sample Output:

adduser command to add a new user

/etc/passwd contains the user account information in the following format.

username:password:userID:groupID:comment:user_directory:shell
  • Username: It is the login name for the user. The username should be between 1-32 characters.
  • Password: It contains the user password in an encrypted format (x).
  • User ID: Every user has a unique User Identification Number (UID). 1001 is the user ID of deepak.
  • Group ID: It shows the primary group ID of a user. 1001 is the primary group ID of deepak.
  • User detail: In between two colons, a GECOS or comment of a user will be displayed if added.
  • Home Directory: The user’s home directory. The default location is the /home directory.
  • Login shell: The login shell for the user. The default login shell is /bin/bash.
Читайте также:  What is linux device sr0

2. Add a system user with adduser command

You can add a new system user using —system option with adduser command.

Sample Output:

adduser command to add a system user

3. adduser command to create a new user group

—group option allows you to create a new user group in the system. The group is created without any users.

Sample Output:

ubuntu@golinux:~$ sudo adduser --group linux Adding group `linux' (GID 1002) . Done.

4. Add a system group with adduser command

We can use —system and —group option together to create a system group in the system. A system user with the same group name is also created.

$ sudo adduser --system --group group

Sample Output:

adduser command to add a system group

5. adduser command to add a new user in different primary group

adduser command adds a new group for a user with the same username. To add a user in a different group, we can use —ingroup option. The group should be already present in the system.

$ sudo adduser --ingroup GROUP user

Sample Output:

adduser command to add a user in different group

6. adduser command to add a user with different home directory

By default, adduser creates the user’s home directory with username under the /home directory. We can create a user’s home directory in a different location using —home option. It also allows us to specify a different name for the user’s home directory.

It is recommended to make sure the new home path doesn’t exist as it will be automatically created by adduser command with proper permission.

$ sudo adduser --home /directory/home_dir_name user 

Sample Output:

Here, we are adding a user ‘sam‘ with its directory ‘record‘ under the /snap directory.

adduser command to add a user with different home directory

7. adduser command to create a user without a home directory

Normally, adduser command automatically creates the user’s home directory when adding a user. We can use —no-create-home option to add a user without its home directory.

$ sudo adduser --no-create-home user

Sample Output:

adduser command to create a user without home directory

As we can see, the default home directory is /home/elliot but it is not created.

check home directory

8. Add a user with specific user ID with adduser command

Every user has a unique user ID in the Linux system. By default, adduser command assigns the next available user ID to a new user. We can use -u or —uid option to add a new user with a custom user ID.

$ sudo adduser -u userID user
$ sudo adduser --uid userID user

Sample Output:

The user chris is assigned with a custom user ID 4567.

adduser command to add a user with custom user ID

9. adduser command to create a user with specific group ID

We have already seen that the adduser command creates a new group with a user name and adds a user to that group. To add a user to a different group, we can use —gid option. The group should be already present in the system.

$ sudo adduser --gid groupID user

Sample Output:

adduser command to add a user with different group ID

10. adduser command to add a user with a custom login shell

adduser command selects the default login shell specified by DSHELL variable in /etc/adduser.conf. The default login shell is /bin/bash. To use a different login shell, we can use —shell option as shown below.

$ sudo adduser --shell SHELL user

Sample Output:

adduser command to create a new user with different shell

11. Add an existing user to an existing group with adduser command

Instead of adding a new user, you can also add an existing user to an existing group using adduser command.

Читайте также:  Облачная платформа для linux

Sample Output:

add existing user to an existing group with adduser command

12. adduser command to create a user with a disabled login

—disabled-login option does not ask to set a password for a new user. The user won’t be able to use the account until the password is set.

$ sudo adduser --disabled-login user

Sample Output:

adduser command to add a user with disabled login

We can set or change the user password in the Linux system by using the following passwd command.

ubuntu@golinux:~$ sudo passwd maxim New password: Retype new password: passwd: password updated successfully

13. Create a user without password using adduser command

—disabled-password also does not ask to set a password when adding a user. It is similar to the above command —disabled-login .

$ sudo adduser --disabled-password user

Sample Output:

adduser command to add a user without password

14. adduser command to add a user with a GECOS or comment

A GECOS or comment field is generally used for keeping the information related to the user. We can use —gecos option to add a GECOS or comment when creating a new user.

$ sudo adduser --gecos GECOS user

Sample Output:

adduser command to add a gecos or comment

15. adduser command to print the debug information

We can use —debug option to print the information in a verbose mode. It is useful when debugging the adduser.

Sample Output:

adduser command to print the debug information

16. Hide informational messages with adduser command

—quiet option hides the informational messages in the output. It does not hide warnings and errors.

Sample Output:

adduser command to suppress informational messages

Conclusion

adduser is a useful command to add a user or group in the Linux system. We hope you have learned to use adduser command from this article. If you still have any confusion, please feel free to ask us in the comment section.

What’s Next

Further Reading

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

Users and groups

Users and groups are used on GNU/Linux for access control—that is, to control access to the system’s files, directories, and peripherals. Linux offers relatively simple/coarse access control mechanisms by default. For more advanced options, see ACL, Capabilities and PAM#Configuration How-Tos.

Overview

A user is anyone who uses a computer. In this case, we are describing the names which represent those users. It may be Mary or Bill, and they may use the names Dragonlady or Pirate in place of their real name. All that matters is that the computer has a name for each account it creates, and it is this name by which a person gains access to use the computer. Some system services also run using restricted or privileged user accounts.

Managing users is done for the purpose of security by limiting access in certain specific ways. The superuser (root) has complete access to the operating system and its configuration; it is intended for administrative use only. Unprivileged users can use several programs for controlled privilege elevation.

Any individual may have more than one account as long as they use a different name for each account they create. Further, there are some reserved names which may not be used such as «root».

Читайте также:  Linux command not found что

Users may be grouped together into a «group», and users may be added to an existing group to utilize the privileged access it grants.

Note: The beginner should use these tools carefully and stay away from having anything to do with any other existing user account, other than their own.

Permissions and ownership

The UNIX operating system crystallizes a couple of unifying ideas and concepts that shaped its design, user interface, culture and evolution. One of the most important of these is probably the mantra: «everything is a file,» widely regarded as one of the defining points of UNIX. This key design principle consists of providing a unified paradigm for accessing a wide range of input/output resources: documents, directories, hard-drives, CD-ROMs, modems, keyboards, printers, monitors, terminals and even some inter-process and network communications. The trick is to provide a common abstraction for all of these resources, each of which the UNIX fathers called a «file.» Since every «file» is exposed through the same API, you can use the same set of basic commands to read/write to a disk, keyboard, document or network device.

A fundamental and very powerful, consistent abstraction provided in UNIX and compatible operating systems is the file abstraction. Many OS services and device interfaces are implemented to provide a file or file system metaphor to applications. This enables new uses for, and greatly increases the power of, existing applications — simple tools designed with specific uses in mind can, with UNIX file abstractions, be used in novel ways. A simple tool, such as cat, designed to read one or more files and output the contents to standard output, can be used to read from I/O devices through special device files, typically found under the /dev directory. On many systems, audio recording and playback can be done simply with the commands, » cat /dev/audio > myfile » and » cat myfile > /dev/audio ,» respectively.

Every file on a GNU/Linux system is owned by a user and a group. In addition, there are three types of access permissions: read, write, and execute. Different access permissions can be applied to a file’s owning user, owning group, and others (those without ownership). One can determine a file’s owners and permissions by viewing the long listing format of the ls command:

total 13740 drwxr-xr-x 2 root root 4096 Jan 12 00:33 grub -rw-r--r-- 1 root root 8570335 Jan 12 00:33 initramfs-linux-fallback.img -rw-r--r-- 1 root root 1821573 Jan 12 00:31 initramfs-linux.img -rw-r--r-- 1 root root 1457315 Jan 8 08:19 System.map26 -rw-r--r-- 1 root root 2209920 Jan 8 08:19 vmlinuz-linux

The first column displays the file’s permissions (for example, the file initramfs-linux.img has permissions -rw-r—r— ). The third and fourth columns display the file’s owning user and group, respectively. In this example, all files are owned by the root user and the root group.

total 16 drwxrwx--- 1 root vboxsf 16384 Jan 29 11:02 sf_Shared

In this example, the sf_Shared directory is owned by the root user and the vboxsf group. It is also possible to determine a file’s owners and permissions using the stat command:

Источник

Оцените статью
Adblock
detector