连接远程主机,就验证身份而言,一般有两种方式,一种是通过用户密码;另一种通过公钥的方式(public key)。
图1、xshell支持验证登录用户的方式
下面就使用public key的方式来实现连接,通过工具ssh-kengen生成密钥对。
注意:操作之前需要ping通本机和目的主机(如果ping不通,可能的原因是防火墙、selinux没关闭,或者网关设置有问题等)
使用xshell,这里使用的是xshell manager 5,目的主机为centos6,将需要连接的远程主机称为目的主机。
目的主机安装ssh服务端,并开启
?
|
1
2
3
4
5
6 |
[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密钥对(包括私钥和公钥)
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 |
[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
?
|
1
2
3 |
passwordauthentication no # 不允许密码验证登录
pubkeyauthentication yes # 允许公钥验证登录
authorizedkeysfile .ssh/id_rsa.pub # 指定公钥文件路径 |
?
|
1
2 |
#]sz id_rsa
#]sz id_rsa.pub |
重载sshd服务
?
|
1
2 |
[root@node1 .ssh]$ service sshd reload
重新载入 sshd: [确定] |
使用xshell连接
?
|
1 |
ssh root@ip |
图2、选择密钥文件
图3、导入私钥并确定
注意:点击确定之后还要重新连接一次
图4、连接成功
客户端使用私钥去验证,而远程主机使用公钥验证。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- 服务器虚拟化技术深度科普 2025-05-27
- 服务器租用价格怎么计算?服务器租用多少钱一年? 2025-05-27
- 云服务器的“弹性”体现在哪些方面? 2025-05-27
- 刀片服务器是什么 刀片服务器的主要特点 2025-05-27
- 利用FTP和计划任务自动备份网站数据和数据库 2025-05-27
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 79
-
2025-05-27 105
-
2025-05-25 70
-
2025-05-27 41
-
2025-05-26 114
热门评论





