linux开启证书密钥SSH登录

1、服务器上制作密钥

[root@host ~]$ ssh-keygen  <== 建立密钥对

Generating public/private rsa key pair.

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

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空

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:

0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host

 

2. 在服务器上安装公钥

键入以下命令,在服务器上安装公钥:

[root@host ~]$ cd .ssh

[root@host .ssh]$ cat id_rsa.pub >> authorized_keys

如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:

 

[root@host .ssh]$ chmod 600 authorized_keys

[root@host .ssh]$ chmod 700 ~/.ssh

 

3. 设置 SSH,打开密钥登录功能

编辑 /etc/ssh/sshd_config 文件,进行如下设置,在后面加入以下三条:

 

RSAAuthentication yes

PubkeyAuthentication yes

PermitRootLogin yes

另外,请留意 root 用户能否通过 SSH 登录:

 

当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:

PasswordAuthentication no

最后,重启 SSH 服务:

 

[root@host .ssh]$ service sshd restart

 

4、使用客户端登录

使用SFTP工具把私钥id_rsa下载到客户端,并妥善存放好

 

感谢您的阅读,本文由 FC LOG 版权所有。(未允许请勿转载)
Nginx+Haproxy实现负载代理功能
LINUX创建与扩展LVM分区