Introduction to the essence of linux creation users and the essence of linux Creation

Source: Internet
Author: User

Introduction to the essence of linux creation users and the essence of linux Creation

Ref: manually create a user in the/etc/default/useradd configuration file/etc/skel directory of the useradd command

Parameters of the useradd command
[Vincent @ localhost ~] $ Useradd -- help-bash:/usr/sbin/useradd: Permission denied [vincent @ localhost ~] $ Sudo useradd -- help [sudo] password for vincent: Usage: useradd [options] LOGIN useradd-D [options] Options:-B, -- base-dir BASE_DIR base directory for the home directory of the new account-c, -- comment comment gecos field of the new account-d, -- home-dir HOME_DIR home directory of the new account # It can be seen that this parameter can print the default configuration file-D when adding a user, -- defaults print or change default useradd configuration -E, -- expiredate EXPIRE_DATE expiration date of the new account-f, -- inactive INACTIVE password inactivity period of the new account-g, -- gid GROUP name or ID of the primary group of the new account-G, -- groups GROUPS list of supplementary groups of the new account-h, -- help display this help message and exit-k, -- skel SKEL_DIR use this alternative skeleton directory-K, -- key KEY = VALUE overr Ide/etc/login. defs defaults-l, -- no-log-init do not add the user to the lastlog and faillog databases-m, -- create-home create the user's home directory-M, -- no-create-home do not create the user's home directory-N, -- no-user-group do not create a group with the same name as the user-o, -- non-unique allow to create users with duplicate (non-unique) UID-p, -- password PASSWORD encrypted passwo Rd of the new account-r, -- system create a system account-R, -- root CHROOT_DIR directory to chroot into-s, -- shell SHELL login shell of the new account-u, -- uid UID user ID of the new account-U, -- user-group create a group with the same name as the user-Z, -- selinux-user SEUSER use a specific SEUSER for the SELinux user mapping # view the default configuration when adding a user [vincent @ localhost ~] $ Sudo useradd-DGROUP = 100 HOME =/homeINACTIVE =-1 EXPIRE = SHELL =/bin/bashSKEL =/etc/skelCREATE_MAIL_SPOOL = yes [vincent @ localhost ~] $ Sudo useradd-D-s/sbin/nologin # In fact, the output above is the content in the/etc/default/useradd file] $ sudo cat/etc/default/useradd # useradd defaults fileGROUP = 100 HOME =/homeINACTIVE =-1 EXPIRE = SHELL =/sbin/nologinSKEL =/etc/skelCREATE_MAIL_SPOOL = yes
/Etc/default/useradd configuration file

That is, the source of output result printed by useradd-D.

Files in the/etc/skel directory

Files under this directory will be copied to the new user's home directory when creating a user, provided that this user has a home directory

The directory tree is as follows:

[vincent@localhost ~]$ sudo ls -la /etc/skel/total 24drwxr-xr-x.  2 root root   59 Mar 22 11:14 .drwxr-xr-x. 74 root root 8192 Mar 22 13:47 ..-rw-r--r--.  1 root root   18 Nov 20  2015 .bash_logout-rw-r--r--.  1 root root  193 Nov 20  2015 .bash_profile-rw-r--r--.  1 root root  231 Nov 20  2015 .bashr
Create a user manually

1. Create a home directory for the user

$ sudo mkdir /home/annie[sudo] password for vincent: 

2. copy the files used for logon and logout to the new user directory.

[vincent@localhost ~]$ sudo ls /etc/skel/ -a.  ..  .bash_logout  .bash_profile  .bashrc[vincent@localhost ~]$ sudo cp /etc/skel/.bash_logout  /etc/skel/.bashrc /etc/skel/.bash_profile /home/annie/

3. Modify related configuration files

/Etc/passwd
$ grep annie /etc/passwdannie:x:1001:1001:vincent:/home/annie:/bin/bash
/Etc/shadow
$ sudo grep annie /etc/shadow annie:$6$PiTiKh9B$Da4VaaR0qlk55r1VFyX3OfQfgj944xExTIdAsyVVTqjmf/u.On8MAfkV0B9RQg5E/OzWj2nYEHGnX.M8feXE3/:17612:0:99999:7:::
/Etc/group
$ sudo grep annie /etc/group annie:x:1001:annie

4. Change the password and test logon.

[vincent@localhost ~]$ sudo passwd annie Changing password for user annie.New password: BAD PASSWORD: The password is shorter than 8 charactersRetype new password: passwd: all authentication tokens updated successfully.[vincent@localhost ~]$ [vincent@localhost ~]$ [vincent@localhost ~]$ su - annie Password: Last failed login: Thu Mar 22 17:26:18 EDT 2018 on pts/1There was 1 failed login attempt since the last successful login.[annie@localhost ~]$ [annie@localhost ~]$ id uid=1001(annie) gid=1001(annie) groups=1001(annie)[annie@localhost ~]$ who am i vincent  pts/1        2018-03-22 17:23 (172.16.81.1)[annie@localhost ~]$ id annie uid=1001(annie) gid=1001(annie) groups=1001(annie)[annie@localhost ~]$ logout

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.