重庆思庄Oracle、Redhat认证学习论坛

标题: ssh无法免密登录 [打印本页]

作者: denglj    时间: 2022-3-23 13:22
标题: ssh无法免密登录
系统:CentOS 7.9
ssh互信做完后发现仍然无法ssh免密登录,提示如下:
[oracle@hisdb1:/home/oracle]$ ssh hisdb1 date
Enter passphrase for key '/home/oracle/.ssh/id_rsa':

解决方案:
[root@hisdb1 .ssh]# vi /etc/ssh/sshd_config
确认以下参数被注释:
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#PermitEmptyPasswords no
确认以下未被注释:
PasswordAuthentication yes

保存后,重启sshd服务
[root@hisdb1 ~]# service sshd restart

使用ssh-keygen重新生成密匙
[oracle@hisdb1:/home/oracle]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_rsa):
/home/oracle/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/oracle/.ssh/id_rsa.
Your public key has been saved in /home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:eiCXx/pZCDM49ljwkQ9NPRR7W25kz5FilY10HAEfIyk oracle@hisdb1
The key's randomart image is:
+---[RSA 2048]----+
|        .oo. ++O*|
|       +  oE .=o*|
|    . + . ..oo++ |
|     + *   ..*.o.|
|    = X S   . o o|
|   . B O .   .   |
|    . + o .      |
|       o o       |
|        o        |
+----[SHA256]-----+

说明:如上所示,该命令会在/home/oracle/.ssh/目录下生成以下两个文件
id_rsa 私钥文件
id_rsa.pub 公钥文件

将公钥复制到远程机器的authorized_keys文件中:
复制到hisdb1:
[oracle@hisdb1:/home/oracle]$ ssh-copy-id -i /home/oracle/.ssh/id_rsa.pub oracle@hisdb1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/oracle/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
oracle@hisdb1's password:  

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'oracle@hisdb1'"
and check to make sure that only the key(s) you wanted were added.

复制到hisdb2:
[oracle@hisdb1:/home/oracle]$ ssh-copy-id -i /home/oracle/.ssh/id_rsa.pub oracle@hisdb2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/oracle/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
oracle@hisdb2's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'oracle@hisdb2'"
and check to make sure that only the key(s) you wanted were added.

验证:
[oracle@hisdb1:/home/oracle]$ ssh hisdb1 date
Mon Mar 14 23:01:02 CST 2022
[oracle@hisdb1:/home/oracle]$ ssh hisdb2 date
Mon Mar 14 23:01:05 CST 2022
[oracle@hisdb1:/home/oracle]$ ssh hisdb1-priv date
Mon Mar 14 23:01:11 CST 2022
[oracle@hisdb1:/home/oracle]$ ssh hisdb2-priv date
Mon Mar 14 23:01:15 CST 2022






欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2