Xshell 是一个强大的安全终端模拟软件,它支持 SSH1, SSH2, 以及 Microsoft Windows 平 台的 TELNET 协议。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、连接成功
客户端使用私钥去验证,而远程主机使用公钥验证。
来源: http://www.phperz.com/article/17/0714/336646.html