linux命令詳解-useradd,groupadd
我們在linux命令列中輸入useradd:
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 -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
後面是其選項
groupadd [-g gid] [-o]] [-r] [-f] groupname
我們在使用linux命令時候應該清楚的是linux命令的格式,比如說上面的是我們在系統中建立一個組
我們需要用到的命令是groupadd那麼後面的[-g gid][-o]是一些options我們可以進行選擇,也可以不選擇
比如說我們需要建立一個組,她的名字為stone我們就可以在命令列中輸入:
# groupadd stone
如果我們建立一個使用者組,並且在建立的時候新增一個id可以這樣來進行:
# groupadd -g 999 stone1
在這個地方我們可以看到的是中括號裡面的東西用或者不用都是可以的,如果我們在建立該使用者組的時候,希望新增更多的資訊,我們可以這樣來使用,只是我們需要知道的是每一個選擇專案所表示的意義
我們不需要記這些選項的含義,因為當我們想使用某一個命令的時候我們們直接將該命令輸入到linux命令列中然後回車就可以將裡面一些選項顯示出來了
[root@VM_51_116_centos ~]# groupmod
Usage: groupmod [options] GROUP
Options:
-g, --gid GID change the group ID to GID
-h, --help display this help message and exit
-n, --new-name NEW_GROUP change the name to NEW_GROUP
-o, --non-unique allow to use a duplicate (non-unique) GID
-p, --password PASSWORD change the password to this (encrypted)
PASSWORD
比如上面我們在命令列中輸入groupmod然後回車就顯示出來我們所需要的選項
# groupmod -n stone2 stone1
比如我們給stone1這個組進行修改名字,我們可以這樣寫,這樣stone1組名就變成了stone2
比如在修改之後我們再去刪除組stone1
[root@VM_51_116_centos ~]# groupdel stone1
groupdel: group 'stone1' does not exist
也就是說stone1這個時候已經不存在了
我們來看看刪除stone2
[root@VM_51_116_centos ~]# groupdel stone2
刪除成功
下面我們來建立一個使用者:useradd -u datouniao
#useradd -u 888 -o datouniao
[root@VM_51_116_centos ~]#
這個表示建立使用者是成功的
下面我們做的事情是為新的使用者建立密碼
使用#passwd datouniao
我們為datouniao這個使用者建立密碼
[root@VM_51_116_centos ~]# userdel -r samll
上面是刪除一個使用者,同時刪除這個使用者的資料夾
[root@VM_51_116_centos ~]# usermod -g stone datouniao
上面的語句是將datouniao這個使用者加入到組stone中