zoukankan      html  css  js  c++  java
  • 基于Xshell使用密钥方式连接远程主机

    基于Xshell使用密钥方式连接远程主机

    连接远程主机,就验证身份而言,一般有两种方式,一种是通过用户密码;另一种通过公钥的方式(Public Key)。

    图1  xshell支持验证登录用户的方式

    下面就使用Public Key的方式来实现连接,通过工具ssh-kengen生成密钥对。

    注意:操作之前需要ping通本机和目的主机(如果ping不通,可能的原因是防火墙、SELinux没关闭,或者网关设置有问题等)

    使用XShell,这里使用的是XShell manager 5,目的主机为CentOS6,将需要连接的远程主机称为目的主机。

    目的主机安装ssh服务端,并开启

    [root@node1 ~]$ yum install -y openssh-server   # 安装openssh服务端
    [root@node1 ~]$ yum install -y openssh-clients     #安装openssh客户端,可以不安装 
    [root@node1 ~]$ service sshd start     # 临时开启sshd服务
    [root@node1 ~]$ chkconfig sshd on      # 永久开启sshd服务,服务器重启也生效
    [root@node1 ~]$service sshd status     # 查看sshd服务运行状态
    openssh-daemon (pid 1384) 正在运行...      # 显示正在运行

    生成ssh密钥对(包括私钥和公钥)

    复制代码
    [root@node1 ~]$ (umask 0077; ssh-keygen)     #  生成ssh密钥对,并将权限设置为600
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa):   # 回车
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    fd:72:10:50:a6:7d:83:c7:93:d2:26:3d:12:0e:38:2f root@node1
    The key's randomart image is:
    +--[ RSA 2048]----+
    |       .o.+      |
    |      o  B * .   |
    |       o. O %    |
    |      E .. O +   |
    |       .S o      |
    |           o     |
    |          . o    |
    |           o     |
    |                 |
    +-----------------+
    [root@node1 ~]$ cd .ssh/
    [root@node1 .ssh]$ ll   #  查看密钥/公钥对信息,权限都为600
    总用量 8
    -rw-------. 1 root root 1675 5月  21 14:26 id_rsa     # 私钥
    -rw-------. 1 root root  392 5月  21 14:26 id_rsa.pub   # 公钥
    [root@node1 .ssh]$ 
    复制代码

    修改sshd连接配置文件vim /etc/ssh/sshd_config

    PasswordAuthentication no        # 不允许密码验证登录
    PubkeyAuthentication yes          # 允许公钥验证登录
    AuthorizedKeysFile .ssh/id_rsa.pub  # 指定公钥文件路径

    将ssh密钥对导出到本机,建议创建一个目录专用放置密钥对

    #]sz id_rsa
    #]sz id_rsa.pub

    重载sshd服务

    [root@node1 .ssh]$ service sshd reload
    重新载入 sshd:                                            [确定]

    使用XShell连接

    ssh root@IP

    图2  选择密钥文件

    图3  导入私钥并确定

    注意:点击确定之后还要重新连接一次

    图4  连接成功

    客户端使用私钥去验证,而远程主机使用公钥验证。 

    XShell连接CentOS 7.2显示中文乱码问题的解决方法  http://www.linuxidc.com/Linux/2017-03/141385.htm 

    Xshell输入中文乱码问题的解决  http://www.linuxidc.com/Linux/2017-09/146931.htm 

    VMware下Ubuntu虚拟机NAT模式连接Xshell  http://www.linuxidc.com/Linux/2016-09/135366.htm 

    Xshell5连接VirtualBox虚拟机中的Ubuntu  http://www.linuxidc.com/Linux/2016-08/134086.htm 

    Xshell连接本地 VirtualBox Ubuntu  http://www.linuxidc.com/Linux/2017-04/142445.htm 

    使用XShell密钥认证登录Linux服务器  http://www.linuxidc.com/Linux/2017-06/144405.htm 

    XShell本地上传文件到Ubuntu上及从Ubuntu下载文件到本地  http://www.linuxidc.com/Linux/2017-06/145191.htm 

    使用Xshell连接Ubuntu详解  http://www.linuxidc.com/Linux/2017-08/146222.htm 

    本文永久更新链接地址http://www.linuxidc.com/Linux/2017-10/148079.htm

  • 相关阅读:
    NOI2015 小园丁和老司机
    退役记
    留言板
    $mathfrak {reputation}$
    计算几何基础
    HNOI2018简要题解
    JXOI2018简要题解
    BJOI2018简要题解
    HAOI2018 简要题解
    CQOI2018简要题解
  • 原文地址:https://www.cnblogs.com/netflix/p/12111991.html
Copyright © 2011-2022 走看看