一、添加一個用戶
1、添加一個新用戶(demon)使用 useradd 命令
# useradd demon
# 設置密碼
# passwd ******
2、useradd 參數:
Options:
-b, --base-dir BASE_DIR
-c, --comment COMMENT
-d, --home-dir HOME_DIR # 指定用戶主目錄
-D, --defaults
-e, --expiredate EXPIRE_DATE
-f, --inactive INACTIVE
-g, --gid GROUP # 指定用戶組
-G, --groups GROUPS # 指定用戶所屬的附加組
-h, --help
-k, --skel SKEL_DIR
-K, --key KEY=VALUE
-l, --no-log-init # 不初始化日志
-m, --create-home # 創建用戶主目錄
-M, --no-create-home # 取消 -m
-N, --no-user-group
-o, --non-unique
-p, --password PASSWORD
-r, --system
-s, --shell SHELL # 指定用戶的登錄 shell
-u, --uid UID # 用戶 ID
-U, --user-group # 用戶組 ID
-Z, --selinux-user SEUSER
二、將用戶添加到某一個組
1、查看用戶所屬的組
# id demon
uid=500(demon) gid=500(demon) 組=500(demon)
2、創建時添加用戶到某個組
# useradd -G 組名 demon
3、添加一個以存在的用戶到組
# usermod -a -G 組名 demon
三、給新用戶(demon)賦予不需要密碼的 sudo 權限,并驗證
# 切換到超級用戶,打開 /etc/sudoers 文件
[root@Demon proc]# vim /etc/sudoers
# 找到 root ALL=(ALL) ALL,在它的下面一行寫入如下配置:
demon ALL=(ALL) NOPASSWD: ALL
# 然后鍵入命令“x!”強制保存并退出