Details about useradd and adduser in Centos and ubuntu

Source: Internet
Author: User
For details, refer to Centos and useradd and adduser in ubuntu. remember that I wrote a blog about the commands adduser and useradd for creating a new user in ubuntu10.04. URL: http://www.2cto.com/ OS /201206/136047.htmlits many articles on the Internet in real time... for details, refer to Centos and useradd and adduser in ubuntu. remember that I wrote a blog about the commands "adduser" and "useradd" for creating a new user in ubuntu10.04 ". Web site: http://www.2cto.com/ OS /201206/136047.html at that time saw a lot of online articles said the two commands are actually the same effect, but I tried in ubuntu10.04 found that not the same. 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. Www.2cto.com first, let's take a look at the Centos Directory. run the [cpp] [root @ localhost sbin] # ll | grep useradd command to view the following results:

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. go to the/usr/sbin directory and run the [cpp] [root @ localhost sbin] # ll | grep useradd command to view the following result: www.2cto.com.

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: [cpp] [root @ localhost sbin] # ll | grep adduser www.2cto.com

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. Prepared by AI_Net

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.