权限与 SSH¶
用户、组与文件权限¶
# 查看当前身份与所属组
id
# 创建用户并加入附加组
sudo useradd -m -s /bin/bash alice
sudo usermod -aG wheel alice # RHEL/CentOS 常见 sudo 组
# 查看文件权限与属主
ls -l /path/to/file
sudo chown alice:dev /path/to/file
sudo chmod 640 /path/to/file
常见权限:640 表示属主可读写、属组只读;755 常用于可执行脚本或目录。不要为了省事使用 chmod -R 777。
SSH 密钥登录¶
# 本地生成密钥
ssh-keygen -t ed25519 -C "your-name"
# 将公钥安装到服务器
ssh-copy-id alice@server.example.com
# 测试登录
ssh alice@server.example.com
确认密钥登录正常后,再在 /etc/ssh/sshd_config 中按需设置 PasswordAuthentication no 和 PermitRootLogin no,每次修改后先检查配置再重载服务: