2.安装SSH,实现SSH无密码登陆
安装SSH:sudo apt-get install openssh-server
实现SSH无密码登录:
此处参考这个文档:linux.chinaunix.net/techdoc/net/2007/08/08/964784.shtml“》http://linux.chinaunix.net/techdoc/net/2007/08/08/964784.shtml
非常详尽。摘录如下:
*************************
服务器之间建立信任关系,对于监控服务器管理很必要。这里介绍ssh的无密码登陆。
本机ip:192.168.1.6
[root@codfei ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y (以为我是第2次建立关系所以此处覆盖原来的文件)
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:
04:37:13:2a:4b:10:af:c1:2b:03:3f:6b:27:ce:b9:62 root@codfei
[root@codfei ~]# cd .ssh/
[root@codfei .ssh]# ll
-rw------- 1 root root 883 Apr 25 17:51 id_rsa
-rw-r--r-- 1 root root 221 Apr 25 17:51 id_rsa.pub
-rw-r--r-- 1 root root 442 Apr 25 17:37 known_hosts
id_rsa是密钥文件,id_rsa.pub是公钥文件。
[root@codfei .ssh]# scp id_rsa.pub192.168.1.4:/root/.ssh/192.168.1.6
root@192.168.1.4‘s password:
id_rsa.pub 100% 221 0.2KB/s 00:00
这里把公钥文件取名为本机的ip地址就是为了以后和更多的机器建立信任关系不发生混淆。
现在登陆到192.168.1.4机器
[root@codfei ~]# cd .ssh/
[root@codfei .ssh]# cat 192.168.1.6 》》 authorized_keys
然后回到192.168.1.6机器直接
[root@codfei .ssh]# ssh 192.168.1.4
Last login: Wed Aug 8 12:14:42 2007 from 192.168.1.6
这样就可以了,里面偶尔涉及到权限问题。一般。/ssh文件夹是755 authorized_keys为600或者644