Linux 服务器使用密钥登录,关闭密码方式

首先登录服务器生成密钥对:

[jiucool@localhost ~]$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_jiucool -C "id_rsa for jiucool.org"
Generating public/private rsa key pair.
Created directory '/home/jiucool/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/jiucool/.ssh/id_rsa_jiucool.
Your public key has been saved in /home/jiucool/.ssh/id_rsa_jiucool.pub.
The key fingerprint is:
05:f8:a8:d8:c1:01:da:03:e0:0f:14:08:23:42:b5:5a id_rsa for jiucool
The key's randomart image is:
+--[ RSA 2048]----+
|%++o   ..        |
|*=  o .  .       |
|.ooE . o  .      |
|  =.o . ..       |
| . + o  S        |
|  . o            |
|                 |
|                 |
|                 |
+-----------------+

进入目录,我们可以看到,已经生成了一对公钥也私钥

[jiucool@localhost ~]$ cd ./.ssh
[jiucool@localhost .ssh]$ ls
id_rsa_jiucool  id_rsa_jiucool.pub
[jiucool@localhost .ssh]$

接着进行,对公钥进行改名:
[jiucool@localhost .ssh]$ mv id_rsa_jiucool.pub authorized_keys
chmod 600 ./*

然后 vi 修改 配置文件 ,将如下几项值进行修改
vi /etc/ssh/sshd_config

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile	.ssh/authorized_keys
PasswordAuthentication no

重启ssh服务
sudo service sshd restart
我们将上述生成的私钥文件,导入到客户端SSH中就可以使用了。

Leave a Reply


正在读取数据……