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中