侧边栏壁纸
  • 累计撰写 73 篇文章
  • 累计创建 30 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

SSH密钥登录

欧泡果奶
2022-03-13 / 0 评论 / 0 点赞 / 242 阅读 / 0 字

1. 制作密钥对

ssh-keygen  <== 建立密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空
Enter same passphrase again: <== 再输入一遍密钥锁码
Your identification has been saved in /root/.ssh/id_rsa. <== 私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥

2. 在服务器上安装公钥

cd .ssh
cat id_rsa.pub >> authorized_keys

如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:

chmod 600 authorized_keys
chmod 700 ~/.ssh

3. 设置SSH,打开密钥登录功能

编辑 /etc/ssh/sshd_config 文件,进行如下设置:

# 允许root认证登录
PermitRootLogin yes
# 允许密钥认证
RSAAuthentication yes
PubkeyAuthentication yes
# 默认公钥存放的位置
AuthorizedKeysFile  .ssh/authorized_keys
# 禁用密码登录
PasswordAuthentication no

重启 SSH 服务

service sshd restart

4. 将私钥下载到客户端,并删除服务器端公私钥

0
SSH

评论区