Linux远程SSH方式使用证书安全登录(咋个办呢-zgbn)

来源:互联网 发布:淘宝上的止鼾器有用吗 编辑:程序博客网 时间:2024/06/02 04:27

Linux远程SSH方式使用证书安全登录

服务器:阿里云服务器
操作系统:CentOS 7(Linux)
远程客户端:Xshell5(SSH 证书)
登录用户:root

在服务端创建公钥和私钥

使用root用户登录系统,并处于当前root用户默认的目录下。

[root@iZ28snxdn5mZ ~]# whoroot     pts/0        2017-12-03 14:06 (123.114.108.80)[root@iZ28snxdn5mZ ~]# pwd/root[root@iZ28snxdn5mZ ~]#

执行ssh-keygen -t rsa命令创建公钥私钥文件。

[root@iZ28snxdn5mZ ~]# ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/root_rsaCreated directory '/root/.ssh'.Enter passphrase (empty for no passphrase): #设置密码#Enter same passphrase again: #设置密码#[root@iZ28snxdn5mZ ~]# ll .sshtotal 2-rw------- 1 root root 1766 Dec  3 16:23 root_rsa-rw-r--r-- 1 root root  399 Dec  3 16:23 root_rsa.pub[root@iZ28snxdn5mZ ~]#

进入.ssh秘钥所在目录

[root@iZ28snxdn5mZ ~]# cd .ssh[root@iZ28snxdn5mZ .ssh]# pwd/root/.ssh

将公钥导入当前用户登录脚本中

[root@iZ28snxdn5mZ .ssh]# cat ./root_rsa.pub >> ./authorized_keys[root@iZ28snxdn5mZ .ssh]# lltotal 12-rw-r--r-- 1 root root  399 Dec  3 16:28 authorized_keys-rw------- 1 root root 1766 Dec  3 16:23 root_rsa-rw-r--r-- 1 root root  399 Dec  3 16:23 root_rsa.pub

设置用户登录秘钥和登录脚本权限

[root@iZ28snxdn5mZ ~]# pwd/root[root@iZ28snxdn5mZ ~]# chown -R 700 .ssh[root@iZ28snxdn5mZ .ssh]# chown -R 644 .ssh/authorized_keys

修改ssh配置文件属性

[root@iZ28snxdn5mZ etc]# vi /etc/ssh/sshd_config

调整下面的属性参数
StrictModes no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

重启一下ssh服务

[root@iZ28snxdn5mZ .ssh]# systemctl restart sshd.service

Xshell5客户端通过证书连接服务器

创建一个连接会话,填写主机连接信息。

这里写图片描述

从服务器上下载生成的秘钥文件,导入到客户端连接中。

这里写图片描述

原创粉丝点击