Ubuntu 设置 SSH 通过密钥登录
henry.huang

1. 制作秘钥对

1
ssh-keygen

2. 在服务器上安装公钥

1
2
cd ~/.ssh
cat id_rsa.pub >> authorized_keys

保证以下文件权限正确

1
2
chmod 600 authorized_keys
chmod 700 ~/.ssh

3. 配置SSH,打开秘钥登录功能

1
sudo vim /etc/ssh/sshd_config

然后按i进入编辑模式,在空白位置输入:

1
2
RSAAuthentication yes
PubkeyAuthentication yes

注意root 用户能否通过 SSH 登录, 如果需要进行如下设置:

1
PermitRootLogin yes

此时已经设置好了使用秘钥登录了,但是如果需要禁用密码登录可以进行如下设置

1
PasswordAuthentication no

4. 重启 SSH 服务

1
service sshd restart
 评论