本文记录了使用秘钥ssh到ubuntu的方法
步骤
- “客户端”创建秘钥,可参考Git - 秘钥创建
- “服务端”开启sshd服务,可参考Ubuntu - 基础配置
- "服务端"允许秘钥登录,详见“服务端”配置
- 保存“客户端”公钥到本地,详见“保存“客户端”公钥
- 重启sshd服务,
sudo systemctl restart sshd
“服务端”配置
sudo vim /etc/ssh/sshd_config
# 开启秘钥登录
PubkeyAuthentication yes
# 同时也可将密码登录关闭
# PasswordAuthentication no
保存“客户端”公钥
# “客户端”公钥内容复制到authorized_keys中
# 该文件的权限是600
cat id_rsa.pub >> ~/.ssh/authorized_keys
# chmod 600 ~/.ssh/authorized_keys