Debian 与 Sedebian 用户管理指南
适用范围与说明
常用用户管理命令
sudo adduser username(会提示设置密码与基本信息)sudo useradd -m -u 1010 -g users -s /bin/bash username(-m 创建家目录,-u 指定 UID,-g 指定主组,-s 指定登录 Shell)sudo deluser usernamesudo deluser --remove-home usernamesudo deluser --remove-all-files usernamesudo usermod -l new_username old_usernamesudo usermod -d /new/home/dir -m usernamesudo usermod -s /bin/zsh usernamesudo passwd -l username / sudo passwd -u usernamesudo passwd usernameid username、groups usernamecat /etc/passwdgetent passwd username用户组与权限管理
sudo groupadd groupnamesudo groupdel groupnamesudo usermod -aG groupname usernamesudo gpasswd -d username groupnamels -lchmod 755 file、chmod 700 dirsudo chown username:groupname file、sudo chgrp groupname dirsudo apt install acl;设置 ACL:sudo setfacl -m u:username:rwx file;查看 ACL:getfacl filesudo visudousername ALL=(ALL:ALL) ALL%admins ALL=(ALL:ALL) ALLSSH 与登录安全
cat ~/.ssh/id_rsa.pub | ssh username@host 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'sudo nano /etc/ssh/sshd_config → AllowUsers user1 user2Match User usernameChrootDirectory /home/usernameForceCommand internal-sftpsudo systemctl restart sshdlast username实用建议与注意事项
pgrep -u username 查看、kill 结束),再进行删除操作。visudo,避免语法错误导致系统无法获取管理员权限。