创建用户
sudo adduser 用户名 (实际是使用一个脚本文件) 不能使用大写字母
sailfish@DESKTOP-GSV91L5:~$ sudo adduser snow [sudo] password for sailfish: Adding user `snow' ... Adding new group `snow' (1001) ... Adding new user `snow' (1001) with group `snow' ... Creating home directory `/home/snow' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for snow Enter the new value, or press ENTER for the default Full Name []: snow Room Number []: snow Work Phone []: snow Home Phone []: Other []: Is the information correct? [Y/n] y
sudo useradd -s /bin/bash -g Robin -d /home/addname -m addname
-s ——指定用户使用的bash
-g——指定用户的组
-d——指定用户的目录
-m——指定用户的目录不存在则创建一个
提示组不存在,创建一个组
sudo groupadd addname
修改用户密码 sudo passwd add name
切换用户 su 用户名
查看当前用户 whoami
删除用户(如果在当前用户下面,删除当前用户,程序会报错)
sudo deluser delname(不会删除home下面文件夹)
sailfish@DESKTOP-GSV91L5:/home$ sudo deluser snow [sudo] password for sailfish: Removing user `snow' ... Warning: group `snow' has no more members. userdel: user snow is currently used by process 5094 /usr/sbin/deluser: `/usr/sbin/userdel snow' returned error code 8. Exiting.
sudo userdel -r delname
查看当前Linux用户/etc/passwd
sailfish@DESKTOP-GSV91L5:~$ cat /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin syslog:x:102:106::/home/syslog:/usr/sbin/nologin messagebus:x:103:107::/nonexistent:/usr/sbin/nologin _apt:x:104:65534::/nonexistent:/usr/sbin/nologin lxd:x:105:65534::/var/lib/lxd/:/bin/false uuidd:x:106:110::/run/uuidd:/usr/sbin/nologin dnsmasq:x:107:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin landscape:x:108:112::/var/lib/landscape:/usr/sbin/nologin sshd:x:109:65534::/run/sshd:/usr/sbin/nologin pollinate:x:110:1::/var/cache/pollinate:/bin/false sailfish:x:1000:1000:,,,:/home/sailfish:/bin/bash