secure shell原理:
密匙认证需要依靠密匙,首先创建一对密匙(包括公匙和密匙,并且用公匙加密的数据只能用密匙解密),并把公匙放到需要远程服务器上。这样当登录远程服务器时,客户端软件就会向服务器发出请求,请求用你的密匙进行认证。服务器收到请求之后,先在你在该服务器的宿主目录下寻找你的公匙,然后检查该公匙是否是合法,如果合法就用公匙加密一随机数(即所谓的challenge)并发送给客户端软件。客户端软件收到 “challenge”之后就用私匙解密再把它发送给服务器。因为用公匙加密的数据只能用密匙解密,服务器经过比较就可以知道该客户连接的合法性。
客户机:172.16.142.4
远端主机:172.16.142.5
在客户机以root用户执行下述命令:
[root@localhost .ssh]# /usr/bin/ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
30:f6:d7:2a:ac:56:eb:3f:fa:40:25:8d:90:96:68:cb root@localhost.localdomain
------------------------------------------------
说明:
该命令将在用户的主目录/.ssh目录下面产生一对密钥
一般采用的ssh的rsa密钥:
id_rsa 私钥
id_rsa.pub 公钥
下述命令产生不同类型的密钥
ssh-keygen -t dsa
ssh-keygen -t rsa
ssh-keygen -t rsa1
-------------------------------------------------------
[root@localhost .ssh]# scp /root/.ssh/id_rsa.pub root@172.16.142.5:/root/.ssh/authorized_keys
The authenticity of host '172.16.142.5 (172.16.142.5)' can't be established.
RSA key fingerprint is 4b:a5:74:fb:2e:08:60:af:fa:76:d4:b0:26:4c:13:75.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.142.5' (RSA) to the list of known hosts.
root@172.16.142.5's password:
id_rsa.pub 100% 236 0.2KB/s 00:00
-------------------------------------------------------------
说明:
将公钥拷贝到远端主机,并写入授权列表文件
你也可以把公钥文件拷贝过去后,在远端主机下直接执行
touch /root/.ssh/authorized_keys
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
-------------------------------------------------------------
操作完毕,登陆检查。
[root@localhost .ssh]# ssh 172.16.142.5
root@172.16.142.5's password:
请注意此时如果仍提示输入密码,请检查如下文件夹和文件的操作权限,这是非常重要的, 否则ssh公钥认证体制不能正常工作:
172.16.142.4(客户端)
/home/root文件夹的权限是600
/home/root/.ssh文件夹的权限是600 (好像这个权限关系不是很大)
/home/root/.ssh/id_dsa私钥的权限600
172.16.142.5(远端主机)
/home/root文件夹的权限是644
/home/root/.ssh文件夹的权限是644 (好像这个权限关系不是很大)
/root/.ssh/authorized_keys公钥的权限644
--------------------------------------------------------------
[root@localhost ~]# ssh 172.16.142.5
Last login: Sat Dec 15 21:10:17 2007 from 172.16.142.4
[root@localhost ~]#
无密码SSH登陆成功!
建立用户等效性
在rac1上执行
rac1-> mkdir ~/.ssh
rac1-> chmod 700 ~/.ssh
rac1-> ssh-keygen -t rsa
rac1-> ssh-keygen -t dsa
在rac2上执行
Rac2-> mkdir ~/.ssh
Rac2-> chmod 700 ~/.ssh
Rac2-> ssh-keygen -t rsa
Rac2-> ssh-keygen -t dsa
在 rac1 上执行
rac1-> cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
rac1-> cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
rac1-> ssh rac2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
rac1-> ssh rac2 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
rac1-> chmod 600 ~/.ssh/authorized_keys
rac1-> scp ~/.ssh/authorized_keys rac2:~/.ssh/authorized_keys
rac2-> chmod 600 ~/.ssh/authorized_keys
为当前终端 shell 会话启用用户等效性
# su - oracle
$ exec /usr/bin/ssh-agent $SHELL
$ /usr/bin/ssh-add
在每个节点上测试连接。验证当您再次运行以下命令时,系统是否不提示您输入口
ssh rac1 date
ssh rac2 date
ssh rac1-priv date
ssh rac2-priv date
ssh rac1.mybiz.com date
ssh rac2.mybiz.com date
ssh rac1-priv.mybiz.com m date
ssh rac2-priv.mybiz.com date
rsh (remote shell)
要配置无密码的rsh,有多种方法。例如:你可以配置/etc/hosts.equiv或者为每个用户生成一个.rhosts文件。配置时候,通常是写入一个允许的远程计算机名(当然,/etc/hosts中应该有相应的IP),此计算机名应该和DataStage配置文件中的fastname相同。
如果要配置root用户的rsh无密码登陆,还需要vi /etc/securetty,在里面添加rsh rexec rlogin,如果非root用户,这一步可以省去
1首先确认机器是否安装rsh包:
[oracle@linux ~]$ rpm -aq |grep rsh
rsh-0.17-25.4
rsh-server-0.17-25.4
2: 修改/etc/xinetd.d/rsh脚本文件
[root@linux ~]# vi /etc/xinetd.d/rsh
rsh 属于xinetd服务,修改/etc/xinetd.d/rsh脚本文件文件中的选项
将disable 设置为no
# default: on
# description: The rshd server is the server for the rcmd(3) routine and, \
# consequently, for the rsh(1) program. The server provides \
# remote execution facilities with authentication based on \
# privileged port numbers from trusted hosts.
service shell
{
socket_type = stream
wait = no
user = root
log_on_success += USERID
log_on_failure += USERID
server = /usr/sbin/in.rshd
# disable = yes
disable = no
}
3.重启rsh服务
[root@linux ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
4. 检查是否启动: rsh server 监听和TCP 是514。
[root@linux ~]# netstat -an |grep 514
tcp 0 0 0.0.0.0:514 0.0.0.0:* LISTEN
unix 3 [ ] STREAM CONNECTED 44514
5:配置rsh server
修改/etc/securetty文件: echo rsh >>/etc/securetty
如果打算用root作为rsh用户的话:
先用root登录到机器A中进行以下操作:
[root@linux ~]# echo "192.168.7.10 root" >>.rhosts //允许192.168.0.10 以root访问
[root@linux ~]# echo "192.168.7.15 root" >>.rhosts
重启rsh server.
.rhosts一般位于 rsh server服务器相对应账号目录下比如root(与.bash_profile在同一目录)
查看是否配置成功:
[root@linux ~]# more .rhosts
192.168.7.10 root
192.168.7.15 root
6:配置vi /etc/hosts,加入对方的IP和机器名(hostname)。机器名可以参考127.0.0.1一行。
[root@linux ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 linux localhost.localdomain localhost
192.168.7.15 linux #本机ip及机器名
192.168.7.10 hlht #远程服务器ip及机器名
7:配置vi /etc/hosts.equiv
[root@linux ~]# vi /etc/hosts.equiv
127.0.0.1 localhost
192.168.7.10 hlht
192.168.7.15 linux
8:到/etc/pam.d/目录下,把rsh文件中的auth required pam_securetty.so一行用“#”封掉即可(注意修改红色字体一行:加#)
[root@hlht ~]# cd /etc/pam.d
[root@hlht pam.d]# vi rsh
#%PAM-1.0
# For root login to succeed here with pam_securetty, "rsh" must be
# listed in /etc/securetty.
auth required pam_nologin.so
#auth required pam_securetty.so
auth required pam_env.so
auth required pam_rhosts_auth.so
account required pam_stack.so service=system-auth
session required pam_stack.so service=system-auth
9:重启rsh server.
[root@linux ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
10:测试和注意的问题:
登录到192.168.7.10机器进行测试
看是否能看到结果。如果看到
[oracle@linux ~]$ rsh -l oracle 192.168.7.10 ps -ef
connect to address 192.168.7.10: Connection refused
Trying krb4 rsh...
connect to address 192.168.7.10: Connection refused
trying normal rsh (/usr/bin/rsh)
Permission denied.
这是由于权权限问题,一般是由于 .rhosts没有配置正确。.rhosts一般位于
rsh server服务器相对应账号目录下比如root(与.bash_profile在同一目录)
如果看到
[root@linux pam.d]# rsh -l root 192.168.7.10 env|grep PATH
connect to address 192.168.7.10: Connection refused
Trying krb4 rsh...
connect to address 192.168.7.10: Connection refused
trying normal rsh (/usr/bin/rsh)
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/bin:/bin
表示rsh配置成功,可以使用rcp进行远程拷贝。
11.RCP 远程目录拷贝
[root@hlht run]# rcp -r source linux:/opt/oracle/yljs
//linux为刚才配置的192.168.7.15服务器名
connect to address 192.168.7.15: Connection refused
Trying krb4 rcp...
connect to address 192.168.7.15: Connection refused
trying normal rcp (/usr/bin/rcp)
[root@hlht run]#
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8797129/viewspace-692501/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8797129/viewspace-692501/