linux建立使用者的本質介紹,linux建立本質

來源:互聯網
上載者:User

linux建立使用者的本質介紹,linux建立本質

ref: useradd命令的參數 /etc/default/useradd設定檔 /etc/skel目錄下的檔案 手動建立一個使用者

useradd命令的參數
[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       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  # 可以看出,這個參數可以列印添加使用者時預設的設定檔  -D, --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           override /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 password 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# 查看添加使用者時的預設配置[vincent@localhost ~]$ sudo useradd -DGROUP=100HOME=/homeINACTIVE=-1EXPIRE=SHELL=/bin/bashSKEL=/etc/skelCREATE_MAIL_SPOOL=yes[vincent@localhost ~]$ sudo useradd -D -s /sbin/nologin# 其實上面輸出的結果就是/etc/default/useradd檔案裡面的內容]$ sudo cat /etc/default/useradd# useradd defaults fileGROUP=100HOME=/homeINACTIVE=-1EXPIRE=SHELL=/sbin/nologinSKEL=/etc/skelCREATE_MAIL_SPOOL=yes
/etc/default/useradd設定檔

即useradd -D列印的輸出結果的來源

/etc/skel目錄下的檔案

此目錄下的檔案會在建立使用者時,將此目錄下的檔案複製至新建立使用者的家目錄下,前提是這個使用者有家目錄

分類樹如下

[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
手動建立一個使用者

1、建立使用者的家目錄

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

2、拷貝登入、登出使用的檔案於新使用者目錄

[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、修改相關的設定檔

/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、修改密碼,登入測試

[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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.