测试信息:
Hadoop1@Ubuntu:~$ ./generate_ssh_v1 hadoop1 1234
####################################################
generate the rsa public key on ubuntu ...
####################################################
spawn ssh hadoop1@ubuntu
The authenticity of host 'ubuntu (192.168.128.130)' can't be established.
ECDSA key fingerprint is 53:c7:7a:dc:3b:bc:34:00:4a:6d:18:1c:5e:87:e7:e8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ubuntu,192.168.128.130' (ECDSA) to the list of known hosts.
hadoop1@ubuntu's password:
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Mon Sep 23 15:22:03 2013 from ubuntu
ssh-keygen -t rsa -P '' -f /home/hadoop1/.ssh/id_rsa
hadoop1@ubuntu:~$ ssh-keygen -t rsa -P '' -f /home/hadoop1/.ssh/id_rsa
Generating public/private rsa key pair.
Your identification has been saved in /home/hadoop1/.ssh/id_rsa.
Your public key has been saved in /home/hadoop1/.ssh/id_rsa.pub.
The key fingerprint is:
e1:5e:20:9d:4e:11:f8:dc:05:35:08:83:5d:ce:99:ed hadoop1@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
| +=+o+o |
| o..*.+.. |
| .o*.=.. |
| =oo.. |
| S . E |
| . . |
| . |
| |
| |
+-----------------+
hadoop1@ubuntu:~$ ssh-copy-id -i /home/hadoop1/.ssh/id_rsa.pub ubuntu
hadoop1@ubuntu's password:
Now try logging into the machine, with "ssh 'ubuntu'", and check in:
~/.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
hadoop1@ubuntu:~$
####################################################
copy the namenode's authorized_keys to slaves ...
####################################################
spawn ssh hadoop1@hadoop
The authenticity of host 'hadoop (192.168.128.138)' can't be established.
ECDSA key fingerprint is 10:8f:d1:8e:63:0a:af:1e:fb:d9:a8:bb:9a:39:ab:46.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop,192.168.128.138' (ECDSA) to the list of known hosts.
hadoop1@hadoop's password:
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic i686)
* Documentation: https://help.ubuntu.com/
System information as of Tue Aug 6 20:11:49 CST 2013
System load: 0.1 Processes: 76
Usage of /: 24.8% of 7.12GB Users logged in: 2
Memory usage: 34% IP address for eth0: 192.168.128.138
Swap usage: 0%
Graph this data and manage this system at https://landscape.canonical.com/
85 packages can be updated.
45 updates are security updates.
Last login: Tue Aug 6 20:11:16 2013 from 192.168.128.130
hadoop1@hadoop:~$ rm -rf /home/hadoop1/.ssh
hadoop1@hadoop:~$ mkdir /home/hadoop1/.ssh
hadoop1@hadoop:~$ spawn scp /home/hadoop1/.ssh/authorized_keys hadoop1@hadoop:/home/hadoop1/.ssh/
hadoop1@hadoop's password:
authorized_keys 100% 396 0.4KB/s 00:00
hadoop1@ubuntu:~$ ssh ubuntu
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Mon Sep 23 16:13:39 2013 from ubuntu
hadoop1@ubuntu:~$ exit
logout
Connection to ubuntu closed.
hadoop1@ubuntu:~$ ssh hadoop
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic i686)
* Documentation: https://help.ubuntu.com/
System information as of Tue Aug 6 20:12:17 CST 2013
System load: 0.12 Processes: 76
Usage of /: 24.8% of 7.12GB Users logged in: 2
Memory usage: 34% IP address for eth0: 192.168.128.138
Swap usage: 0%
Graph this data and manage this system at https://landscape.canonical.com/
85 packages can be updated.
45 updates are security updates.
Last login: Tue Aug 6 20:11:50 2013 from 192.168.128.130
hadoop1@hadoop:~$ exit
logout
Connection to hadoop closed.
总结:刚开始编写shell的时候连着写 spawn 然后直接敲shell的命令,结果老是expect后面的读不到。。。
更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2
更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13
