服务器ssh

    xiaoxiao2021-03-25  92

    ·生成rsa_key , 并添加公钥到服务器

    windows:

    下载XSHELL,在登陆的时候可以选择用密钥登陆, 然后直接生成,保存可以得到rsa_key.pub。

    linux or Mac:

    1、生成SSH密钥对

    ssh-keygen -t rsa

    2、建议直接回车使用默认路径

    Enter file in which to save the key (/root/.ssh/id_rsa):

    3、输入密码短语(留空则直接回车)

    Enter passphrase (empty forno passphrase):

    4、重复密码短语

    Enter same passphrase again:

    最后会显示生成的路径

    Your identification has been saved in/root/.ssh/id_rsa. Yourpublic key has been saved in/root/.ssh/id_rsa.pub.

    ·添加res_key到服务器

    打开刚才生成的.pub文件,复制里面内容 , 在服务器里面输入

    echo "XXX(.pub里面所有的内容)" >> /root/.ssh/authorized_keys

    ·禁止密码登陆,并启动ssh_key验证

    1、编辑sshd_config文件

    vi /etc/ssh/sshd_config

    2、禁用密码验证

    PasswordAuthentication no

    3、启用密钥验证

    RSAAuthentication yes PubkeyAuthentication yes

    重启服务

    RHEL/CentOS系统: service sshd restart Ubuntu系统: service ssh restart debian系统: /etc/init.d/ssh restart
    转载请注明原文地址: https://ju.6miu.com/read-40277.html

    最新回复(0)