CRT、xshell使用SSH公钥方式登录Linux服务器
ssh-keygen -t rsa
id_rsa 私钥id_rsa.pub 公钥
1、 crt使用ssh公钥方式登陆linux服务器
1.1 crt工具生成密钥
打开SecureCRT客户端,连接服务器,点击工具-->创建公钥
![66a1fdcfac6123d2327df131b639a67a.png](https://img-blog.csdnimg.cn/img_convert/66a1fdcfac6123d2327df131b639a67a.png)
![1e35c094a49298a201f9100d9460432e.png](https://img-blog.csdnimg.cn/img_convert/1e35c094a49298a201f9100d9460432e.png)
![7b0b113d84f4afe0c8faeee39846c3af.png](https://img-blog.csdnimg.cn/img_convert/7b0b113d84f4afe0c8faeee39846c3af.png)
![37bd0e2e15c9e0db0f103cb18e197cb7.png](https://img-blog.csdnimg.cn/img_convert/37bd0e2e15c9e0db0f103cb18e197cb7.png)
![2f0a55e2afb285462ed7e05a0db7fb6b.png](https://img-blog.csdnimg.cn/img_convert/2f0a55e2afb285462ed7e05a0db7fb6b.png)
![eb2c0067c927dfcb3430fd0ab7f8a198.png](https://img-blog.csdnimg.cn/img_convert/eb2c0067c927dfcb3430fd0ab7f8a198.png)
1.2上传密钥到服务器
cd /root/.ssh #上传生成的密钥
cat Identity.pub >authorized_keys
1.3更改ssh配置文件
cat /etc/ssh/sshd_config |grep -v ^$ |grep -v ^#
Port 12588 #ssh连接端口
Protocol 2
SyslogFacility AUTHPRIV
PermitRootLogin yes #root用户登陆
PubkeyAuthentication yes # 默认为注释,启用公钥认证
AuthorizedKeysFile /root/.ssh/authorized_keys # 验证公钥的存放路径
PasswordAuthentication no #密码认证
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
X11Forwarding yes
Subsystem sftp /usr/libexec/openssh/sftp-server
1.4 crt登陆服务器
service sshd restart
Iptables -F
第一次登陆服务器重启,输入通行短语
2、 xshell使用ssh公钥方式登陆linux服务器
2.1 在xshell中配置公私钥
![265e140795b07fd77b54dacbe2339d4e.png](https://img-blog.csdnimg.cn/img_convert/265e140795b07fd77b54dacbe2339d4e.png)
![ca6aaef8abed4c4471dd1ce86a4be063.png](https://img-blog.csdnimg.cn/img_convert/ca6aaef8abed4c4471dd1ce86a4be063.png)
![e575eecf273fccb22addbea6f2cae44f.png](https://img-blog.csdnimg.cn/img_convert/e575eecf273fccb22addbea6f2cae44f.png)
![b20fd9a905e97213e63f0bdd95168e7b.png](https://img-blog.csdnimg.cn/img_convert/b20fd9a905e97213e63f0bdd95168e7b.png)
![4760997f3b1861a95ef409fb7bfc1f08.png](https://img-blog.csdnimg.cn/img_convert/4760997f3b1861a95ef409fb7bfc1f08.png)
2.2上传密钥到服务器
cd /root/.ssh #上传生成的公钥
cat id_rsa_2048 >authorized_keys
2.3更改ssh配置文件
cat /etc/ssh/sshd_config |grep -v ^$ |grep -v ^#
Port 12588 #ssh连接端口
Protocol 2
SyslogFacility AUTHPRIV
PermitRootLogin yes #root用户登陆
PubkeyAuthentication yes # 默认为注释,启用公钥认证
AuthorizedKeysFile /root/.ssh/authorized_keys # 验证公钥的存放路径
PasswordAuthentication no #密码认证
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
X11Forwarding yes
Subsystem sftp /usr/libexec/openssh/sftp-server
2.4 xshell登陆服务器
![32a852a746cebe46c13c4e69733cc7b6.png](https://img-blog.csdnimg.cn/img_convert/32a852a746cebe46c13c4e69733cc7b6.png)
![b2fcf07cae91b44416b9c847eba5bea0.png](https://img-blog.csdnimg.cn/img_convert/b2fcf07cae91b44416b9c847eba5bea0.png)
![4b188889c91cd03b9db774ce31966840.png](https://img-blog.csdnimg.cn/img_convert/4b188889c91cd03b9db774ce31966840.png)