一.生成密钥的公钥和私钥

  1.ssh-keygen -t rsa 

二.将生成的私钥(id_rsa)下载到本地的windows机,并把公钥导入到.ssh/authorized_keys 文件中去

      1.#cd /root/.ssh/

  2.#cat id_rsa.pub > authorized_keys 

三.sshd配置

   1.sshd配置文件路径 /etc/ssh/sshd_config

   2.

四.设置sshd  服务器服务,打开以下设置:

    1. RSAAuthentication yes 

    2. PubkeyAuthentication yes

    3. AuthorizedKeysFile      /root/.ssh/authorized_keys

    4. ChallengeResponseAuthentication no 

    5. PasswordAuthentication no 

    6. UsePAM no 

五.重启ssh服务

    1.   #service ssh  restart (注意:如果是centos7以下版本)

    2.如果是centos7以上  

    查看ssh服务状态:systemctl status sshd.service

    开启ssh服务:systemctl start sshd.service

    重启ssh服务:systemctl restart sshd.service

      服务器自动开启:systemctl enable sshd.service

六.xshell登录

    添加id_rsa私钥文件,输入建立私钥时候的密码,就成功了。

    6b46195ebd1eaed5c52ce8838f23e7e9.png-wh_