Linux服务器配置密钥登录 By SR.李 On 2020-02-10 生成公钥私钥 # 生成密钥可以默认生成,也可以指定具体路径,文件名(根据提示) ssh-keygen -t rsa # 默认在 /root/.ssh/id_rsa (私钥,用于客户端) # 默认在 /root/.ssh/id_rsa.pub (私钥,用于服务端) cd /root/.ssh touch authorized_keys # 将公钥写入文件 cat id_rsa.pub >> authorized_keys chmod 600 authorized_keys vim /etc/ssh/sshd_config BashCopy 修改/etc/ssh/sshd_config以下配置 #启用公告密钥配对认证方式 PubkeyAuthentication yes # 公钥路径 AuthorizedKeysFile .ssh/authorized_keys # 启用 RSA 认证 (可以不做配置) RSAAuthentication yes #禁止密码验证登录,如果启用的话,OpenSSH的 RSA认证登录就没有意义了。 PasswordAuthentication no # root登录 PermitRootLogin yes BashCopy 重启sshd服务 service sshd restart BashCopy 将 /root/.ssh/id_dsa 下载到本地 # 没有命令可以 yum install lrzsz 或者使用scp等方式 sz /root/.ssh/id_rsa BashCopy 测试(注意不要断开之前是ssh链接,万一失败,你可能登不进去服务器)