配置ssh agent远程登录不用输入密码

两台机器:SDB1 和SDB2

均使用帐号oracle远程登录对方,现在需要配置无需密码远程登录。


1 创建.ssh文件夹

在 home directory创建.ssh文件夹

[oracle@sdb2 ~]$ mkdir .ssh
[oracle@sdb2 ~]$ chmod 700 .ssh

2 生成密钥

两种密钥rsa及dsa

[oracle@sdb2 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_rsa): 
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:
9a:53:ee:33:97:45:2d:e1:e6:01:75:c4:d3:7c:fe:41 oracle@sdb2.liteon.com
[oracle@sdb2 ~]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/oracle/.ssh/id_dsa.
Your public key has been saved in /home/oracle/.ssh/id_dsa.pub.
The key fingerprint is:
50:83:6f:60:a3:3f:91:48:a7:f6:30:4b:7c:f6:f9:c4 oracle@sdb2.liteon.com


3 创建authorized_keys

[oracle@sdb2 .ssh]$ touch authorized_keys
[oracle@sdb2 .ssh]$ ls -l
total 36
-rw-r--r-- 1 oracle oinstall    0 Aug  7 14:57 authorized_keys
-rw------- 1 oracle oinstall  736 Aug  7 14:54 id_dsa
-rw-r--r-- 1 oracle oinstall  612 Aug  7 14:54 id_dsa.pub
-rw------- 1 oracle oinstall 1743 Aug  7 14:54 id_rsa
-rw-r--r-- 1 oracle oinstall  404 Aug  7 14:54 id_rsa.pub
[oracle@sdb2 .ssh]$ chmod 600 authorized_keys

4 将公钥传送到sdb2

[oracle@sdb2 .ssh]$ cat id_dsa.pub>>authorized_keys
[oracle@sdb2 .ssh]$ cat id_rsa.pub>>authorized_keys

[oracle@sdb2 .ssh]$ chmod 600 authorized_keys
[oracle@sdb2 .ssh]$ cat id_dsa.pub>>authorized_keys
[oracle@sdb2 .ssh]$ cat id_rsa.pub>>authorized_keys
[oracle@sdb2 .ssh]$ scp authorized_keys sdb1:/home/oracle/.ssh
The authenticity of host 'sdb1 (10.132.98.184)' can't be established.
RSA key fingerprint is ea:5f:7c:7d:6a:2a:11:f0:fb:[oracle@sdb2 .ssh]$ exec ssh-agent $SHELL
[oracle@sdb2 .ssh]$ ssh-add
Enter passphrase for /home/oracle/.ssh/id_rsa: 
Identity added: /home/oracle/.ssh/id_rsa (/home/oracle/.ssh/id_rsa)
Identity added: /home/oracle/.ssh/id_dsa (/home/oracle/.ssh/id_dsa)41:15:a8:89:43:91:a5.
Are you sure you want to continue connecting (yes/no)? yes   
Warning: Permanently added 'sdb1,10.132.98.184' (RSA) to the list of known host

5 在SDB2上重复1至4

 将在SDB2上生成的authorized_keys拷贝至SDB1

6 配置ssh-agent

这一个步骤是需要在每次使用的时候都配置

[oracle@sdb2 .ssh]$ exec ssh-agent $SHELL
[oracle@sdb2 .ssh]$ ssh-add
Enter passphrase for /home/oracle/.ssh/id_rsa: 
Identity added: /home/oracle/.ssh/id_rsa (/home/oracle/.ssh/id_rsa)
Identity added: /home/oracle/.ssh/id_dsa (/home/oracle/.ssh/id_dsa)

[oracle@sdb2 .ssh]$ ssh sdb1 date
Fri Aug  7 15:19:55 CST 2015
[oracle@sdb2 .ssh]$ 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值