Comparison between useradd and adduser in Centos and Ubuntu

Source: Internet
Author: User

In fact, I saw many articles on the internet saying that these two commands actually have the same effect, but I found they are not the same when I tried them on Ubuntu10.04. At that time, I also spoke about the disorderly online articles. Now, after my own experiments, I found that the two commands in different versions of Linux are not exactly the same. I compared Centos with Ubuntu. First, let's take a look at the Centos directory and run the command

 
 
  1. [cpp]
  2. [root@localhostsbin]#ll|grepuseradd

The following result is displayed:

Observe the first and third items in the above results. We can find that the original adduser is linked to useradd. Therefore, in Centos, useradd and adduser have the same functions. After a user is created, a new user record is added to the/etc/passwd file, and the home directory of the new user is created under the/home directory, copy the files in the/etc/skel directory to the directory. Note: New users created in this method cannot log on to the system before setting the password, you need to use the "passwd User Name" method under the root permission to set a password for the specified user. You can log on to the system with the user name and password next time. Next, let's take a look at the Ubuntu system, first go to the/usr/sbin directory and run the following command:

 
 
  1. [cpp]
  2. [root@localhostsbin]#ll|grepuseradd

The following result is displayed:

As you can see, in Ubuntu, useradd and adduser are independent commands, and there is no link between them. I tried to use the useradd command to create a new user (without any useradd parameters ). The results are the same as those in the previous blog post (the article link is at the beginning of this article). There is still no home directory for new users in/home. But this time I also checked a file, that is, the/etc/passwd file. After opening it, I found that the information of my new user is added to/etc/passwd. However, the login Shell of this user is different from that of other users, it is "/bin/sh", and other users' logon shells are/bin/bash. As shown in:

We can modify this file with the root permission so that the login Shell of example is/bin/bash. Then we need to use the mkdir command to create a user directory for this user, that is,/home/example, and copy the files in the/etc/skel directory to the user directory. After setting the password, the new user can log on to the system just like the normal user.

Note: The above case is that no specified parameter of useradd is used, and additional work needs to be done manually. If the useradd parameter "-m" is added and the password is set, the user can log on to the system normally (For details, refer to my previous blog post, link at the beginning of this article ). In addition, it seems that the user created by useradd has/bin/sh by default, which can be changed to/bin/bash under the root permission, you can also specify the parameter "-s" when using useradd.

Now let's take a look at the adduser in Ubuntu10.04, or in/usr/sbin. Run the following command to view the result:

 
 
  1. [cpp]
  2. [root@localhostsbin]#ll|grepadduser

Looking at the above results, we found that adduser and addgroup are also the same command. The adduser command is described in detail in my previous blog post (the link is at the beginning of this article. I will not introduce it here. In Ubuntu, the default logon Shell of the user created by the adduser command is/bin/bash, which is different from useradd.

Based on the above two versions, we found that the commands useradd and adduser are different based on the system version. Linux systems of other versions have not been tested yet, and we hope more discoveries will be made.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.