服务器sshd配置#vim /etc/ssh/sshd_confPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keys#/etc/init.d/sshd restartwindows生成密钥Xshell打开Xshell->工具->新建用户密钥生成向导(W)RSA加密方式,2048位密钥长度->输入公钥名称(wangs_rsa),密钥密码,下一步公钥格式(ssh2-openssh)->保存文件,将公钥保存到本地->完成这是会弹出会话框,里面有你刚刚生成的私钥(与密钥名称相同),选中私钥,点击导出,将私钥导出到本地现在,本地就有一对对应公钥和私钥了(wangs_rsa和wangs_rsa.pub)windows下登录xshell登录将公钥id_rsa.pub上传到目标服务器用户下.ssh目录如果没有可以新建,注意权限#mkdir .ssh#chmod 700 .ssh#cat id_rsa.pub >> authorized_keys#chmod 600 authorized_keys新建登录,输入用户名后,SSH身份验证时选择public key,选择刚刚生成的私钥,如果私钥设置密码,输入密码,否则可即可登录linux 密钥生成#ssh-keygen -t rsa一路回车,根据提示,可以设置名称添加密码等,最后生成一对私钥和公钥linux登录方法1:在密钥生成的机器上# ssh-copy-id -i /root/.ssh/id_rsa.pub root@218.111.89.222#sshroot@218.111.89.222方法2:将公钥id_rsa.pub上传到目标服务器用户下.ssh目录如果没有可以新建,注意权限#mkdir .ssh#chmod 700 .ssh#cat id_rsa.pub >> authorized_keys#chmod 600 authorized_keys#ssh root@218.111.89.222注意私钥一般在.ssh下,权限为700如果无法登录,参照如下命令# ssh-agent bash --login -i# ssh-add id_rsaPS:首次进行ssh链接时,出现以下提示:The authenticity of host '58.221.186.137 (58.221.186.137)' can't be established. RSA key fingerprint is a0:00:d3:33:54:96:40:03:ff:ad:15:a9:59:22:f4:2a. Are you sure you want to continue connecting (yes/no)? 修改文件:#vim /etc/ssh/ssh_config修改如下StrictHostKeyChecking no