Loading

Centos7.5使用SSH密钥登录

12.1、查看操作系统版本

# cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)


12.2、在服务器端创建密钥

# ssh-keygen

我这里设置的秘钥短语为:Liu@Chang


12.3、在服务器上创建公钥并将私钥下载到本地

# cd .ssh/

# ls -l

# cat id_rsa.pub >>authorized_keys

# chmod 600 authorized_keys

# chmod 700 ~/.ssh # 该步骤可以省略

# sz -y id_rsa


12.4、配置ssh,打开秘钥登录功能并禁用使用密码登录

1、常用认证登录参数

PermitRootLogin yes

# 允许root认证登录,默认是注释掉并开启的。

PasswordAuthentication yes

# 默认允许密码认证登录

RSAAuthentication yes

PubkeyAuthentication yes

# 以上两行表示允许密钥认证。"RSAAuthentication yes"

# 参数在centos7.3以后被废弃,使用"PubkeyAuthentication yes"

# 参数,默认启用。

AuthorizedKeysFile .ssh/authorized_keys

# 默认公钥存放的位置


2 修改参数

# vim /etc/ssh/sshd_config

PubkeyAuthentication yes

# 打开允许密钥认证注释

PasswordAuthentication no

# 关闭允许密码认证登录


3 重启sshd服务

# systemctl restart sshd


12.5、在xshell连接中导入秘钥并登录服务器

1 配置连接


2 配置用户身份验证

(1) 导入秘钥

1)

2)

3)


3 连接服务器


4 补充

Centos: 默认允许root和其它用户、非空密码或密钥登录。

Ubuntu:默认允许非root用户、非空密码或密钥登录。

aws: 默认允许root用户和其它用户、密钥登录。











posted @ 2021-04-26 13:14  云起时。  阅读(534)  评论(0编辑  收藏  举报