重庆思庄oracle技术分享-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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值