OpenSSH和ssh-keygen 实现无密码登陆
QQQ 博客改造 53

以下均在root用户下执行!!!

  1. 生成密钥对
[root@host ~]$ 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. <== 公钥
The key fingerprint is:
0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
  1. 为服务器添加公钥
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys
chmod 700 ~/.ssh
  1. 修改ssh配置文件以使其接受密钥登陆
 vim /etc/ssh/sshd_config
# 下面两行取消注释
# PubkeyAuthentication yes
# PermitRootLogin yes
  1. 将私钥下载到客户端,然后转换为 PuTTY 能使用的格式
    windows:
    使用 WinSCP、SFTP 等工具将私钥文件 id_rsa 下载到客户端机器上。然后打开 PuTTYGen,单击 Actions 中的 Load 按钮,载入你刚才下载到的私钥文件。如果你刚才设置了密钥锁码,这时则需要输入。
    载入成功后,PuTTYGen 会显示密钥相关的信息。在 Key comment 中键入对密钥的说明信息,然后单击 Save private key 按钮即可将私钥文件存放为 PuTTY 能使用的格式。
    linux和MacOS:ssh-add即可将私钥添加
    ssh-add id_rsa
OpenSSH和ssh-keygen 实现无密码登陆
https://blog.427221.xyz/archives/openssh%E5%92%8Cssh-keygen%E5%AE%9E%E7%8E%B0%E6%97%A0%E5%AF%86%E7%A0%81%E7%99%BB%E9%99%86
作者
qqq
发布于
更新于
许可