知乎專欄 | 多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者” |
目錄
$ adduser neo
## 添加一個賬號和root有一樣的權限 useradd -o -u 0 -g 0 admin ## 指定家目錄和shell useradd -o -u 0 -g 0 -d /root -s /bin/bash admin ## 添加 root 用戶並且設置密碼 useradd -o -u 0 -g 0 admin echo redhat | passwd admin --stdin // 上面兩條同下面一條 useradd -o -u 0 -g 0 -p $(openssl passwd -1 redhat@@neo) admin ## 添加普通用戶並且設置密碼 useradd -p $(openssl passwd -1 redhat@@admin) admin ## 添加普通用戶指定其第二用戶組 useradd -G root -p $(openssl passwd -1 redhat@@admin) admin
remove an existed user, but keeping directory /home/neo
$ userdel neo
delete user's directory under /home when removing an existed user
$ userdel -r neo
usermod -G group -a user [root@scientific ~]# groupadd vm [root@scientific ~]# adduser xen [root@scientific ~]# usermod -G vm -a xen [root@scientific ~]# usermod -G vm -a kvm [root@scientific ~]# id xen uid=501(xen) gid=502(xen) groups=502(xen),501(vm)
將 www 加入 wheel 組,www 用戶可以使用 sudo 命令
[root@localhost ~]# usermod -aG wheel www [www@localhost ~]$ id www uid=80(www) gid=80(www) groups=80(www),10(wheel)
lock / unlock
passwd -l neo
passwd -u neo
[root@test ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin news:x:9:13:news:/etc/news: uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin gopher:x:13:30:gopher:/var/gopher:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin nscd:x:28:28:NSCD Daemon:/:/sbin/nologin vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin pcap:x:77:77::/var/arpwatch:/sbin/nologin rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin nfsnobody:x:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin avahi:x:70:70:Avahi daemon:/:/sbin/nologin haldaemon:x:68:68:HAL daemon:/:/sbin/nologin avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin neo:x:500:500::/home/neo:/bin/bash mysql:x:501:501::/home/mysql:/bin/bash