ECS CentOS密钥公钥

先说下环境,我用的是阿里云ESC服务器,装载CentOS 7.2的系统盘,没有选择任何的附加包之类的。

        为了安全性的考虑,我想要配置使用公密钥的方式去连接服务器。这里需要修改服务器的SSH服务,主要分为三步:修改服务器SSH配置、客户端生成公钥、服务器加入客户端公钥,下面是我操作的过程:

一. 生成密钥的公钥和私钥

# ssh-keygen -t rsa 

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Created directory '/root/.ssh'.

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:

              1c:37:a8:a3:65:a2:4a:89:ab:46:30:ad:54:d1:40:eb root@iZ28vo50eu5Z

二. 设置sshd  服务器服务

1. 登录服务器,输入命令vi /etc/ssh/sshd_config修改配置文件

2. 找到RSAAuthentication、PubkeyAuthentication、AuthorizedKeyFiles、StrictModes所在的行,如果被#注释了,就取消#号,改为如下配置:

 修改以下设置: 

ChallengeResponseAuthentication no 

PasswordAuthentication no 

UsePAM no 

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeyFiles .ssh/authorized_keys       

StrictModes no

修改好ssh的配置文件后保存并退出,使用systemctl restart sshd.service重启SSH服务。然后导入到远程工具中

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容