- 论坛徽章:
- 0
|
本回复分两部分,第一部分是在两台Linux之间建立互信的过程,之后从客户机登录服务器不需要再键入密码.两台机器分别为:
服务器: RHEL5, 192.168.1.8, 用户为db2inst1
客户端: Fedora5, 192.168.1.10, 用户为wrl
第一部分完全为客户端Fedora5上的操作,拷屏如下,
$cd
$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/wrl/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wrl/.ssh/id_rsa.
Your public key has been saved in /home/wrl/.ssh/id_rsa.pub.
The key fingerprint is:
76:f8:39:0c:50:30:1c:2d:c3:8a:3a:68:74:39:5f:85 wrl@Venus
$ssh -l db2inst1 192.168.1.8 mkdir .ssh; chmod 0700 .ssh
db2inst1@192.168.1.8's password:
$scp .ssh/id_rsa.pub db2inst1@192.168.1.8:.ssh/id_rsa.pub
db2inst1@192.168.1.8's password:
id_rsa.pub 100% 391 0.4KB/s 00:00
$ssh -l db2inst1 192.168.1.8 touch .ssh/authorized_keys2; cat .ssh/id_rsa.pub >>.ssh/authorized_keys2
db2inst1@192.168.1.8's password:
$ssh -l db2inst1 192.168.1.8
Last login: Sat May 9 00:34:17 2009 from 192.168.1.10
$ /home/db2inst1>exit
$
第二部分建立一个名为rssh.sh的脚本文件并执行,结果如下,
$rssh.sh
192.168.1.8 has /tmp directory
192.168.8.8 doesn't have /tmpnotexist directory
$
rssh.sh的代码如下,
#!/bin/ksh
ssh -l db2inst1 192.168.1.8 [[ -d /tmp ]]
if [ $? -eq 0 ]; then
echo "192.168.1.8 has /tmp directory"
else
echo "192.168.8.8 doesn't have /tmp directory"
fi
ssh -l db2inst1 192.168.1.8 [[ -d /tmpnotexist ]]
if [ $? -eq 0 ]; then
echo "192.168.1.8 has /tmpnotexist directory"
else
echo "192.168.8.8 doesn't have /tmpnotexist directory"
fi |
|
|