Ubuntu设置key登录 禁止root

  • 增加用户
useradd yourname
  • 设置密码
passwd yourname
  • 创建目录
mkdir /home/yourname
  • 授权
chown yourname: /home/yourname
  • 设置key登录
vim /etc/ssh/sshd_config
  • 禁止密码验证
PasswordAuthentication no
  • 启用密钥验证
RSAAuthentication yes
PubkeyAuthentication yes
  • 禁止root用户登录
PermitRootLogin no
  • 指定公钥数据库文件
AuthorizedKeysFile .ssh/authorized_keys
  • 重启sshd服务
service sshd restart
  • 可能会提示服务未注册 使用
/etc/init.d/ssh restart
  • 设置yourname用户为sudoers
  • 增加写权限
chmod u+w /etc/sudoers
vim /etc/sudoers
  • 在 root ALL=(ALL) ALL 后面增加一行
yourname ALL=(ALL) ALL
  • 撤销写权限
chmod u-w /etc/sudoers
  • 切换用户
su yourname
cd /home/yourname
  • 创建ssh目录
mkdir .ssh
cd .ssh
  • 创建ssh key
ssh-keygen
  • 设置公钥
cat id_dsa.pub >> authorized_keys
  • 下载私钥 使用私钥登录
sz id_dsa
  • rz命令不存在
sudo apt-get update
sudo apt-get install lrzsz

你可能感兴趣的:(Ubuntu设置key登录 禁止root)