美文网首页Linux 基础操作
SSH的免密码(密钥)登录

SSH的免密码(密钥)登录

作者: baixiaoyeer | 来源:发表于2018-05-13 20:40 被阅读0次

    一、任务要求
    实现免密码登录,即密钥登录。

    二、实验工具
    X-shell 5

    环境:Windows 7 x64
    CentOS-6.5

    三、ssh免密码登录的方法
    1、ssh登录的方法
    1.1 启动CentOS-6.5虚拟机,打开终端查看虚拟机IP地址;


    image.png

    1.2 打开已安装好的X-shell工具,新建ssh用户登录,输入虚拟机名、IP地址,依次输入用户名、密码,点击确认登录(这里选择的是root用户登录);


    image.png
    image.png

    2、生成密钥,导入密钥;
    2.1 使用X-shell 5生成密钥对;


    image.png
    image.png
    image.png
    image.png
    image.png

    2.2 对生成出来的密钥进行保存,便于后续Linux操作系统的密钥导入;


    image.png
    image.png

    3、配置ssh_config文件
    3.1 找到ssh配置文件,从下列代码中可以看出,密钥配置文件为ssh_host_dsa_key;
    [root@localhost ~]# cd /etc/ssh
    [root@localhost ssh]# ls
    moduli ssh_host_dsa_key ssh_host_key.pub
    ssh_config ssh_host_dsa_key.pub ssh_host_rsa_key
    sshd_config ssh_host_key ssh_host_rsa_key.pub


    image.png
    image.png

    3.2 找到密钥配置文件,进行密钥配置;
    [root@localhost ~]# pwd
    /root
    [root@localhost ~]# ls -a
    . .cshrc .gconfd .ICEauthority Public
    .. .dbus .gnome2 install.log .pulse
    anaconda-ks.cfg Desktop .gnote install.log.syslog .pulse-cookie
    .bash_logout Documents .gnupg .local .ssh
    .bash_profile Downloads .gstreamer-0.10 Music .tcshrc
    .bashrc .esd_auth .gtk-bookmarks .nautilus Templates
    .config .gconf .gvfs Pictures Videos
    [root@localhost ~]# vi .ssh/authorized_keys


    image.png

    3.3 导入密钥,保存并退出,重启ssh服务;


    image.png

    [root@localhost ~]# service sshd restart


    image.png

    3.4 然后手动断开X-shell 5与虚拟机的连接,通过添加配置的密钥文件登录;


    image.png
    image.png

    注意:
    如果是多个用户的密钥登录的话,只需要在密钥配置文件中空一行,添加进去就可以实现多用户免密钥登录了。

    相关文章

      网友评论

        本文标题:SSH的免密码(密钥)登录

        本文链接:https://www.haomeiwen.com/subject/tcuqdftx.html