1) 安装:sudo apt-get install ssh
这个安装完后,可以直接使用ssh命令了。
执行$ netstat -nat 查看22端口是否开启了。
测试:ssh localhost。
输入当前用户的密码,回车就ok了。说明安装成功,同时ssh登录需要密码。
(这种默认安装方式完后,默认配置文件是在/etc/ssh/目录下。sshd配置文件是:/etc/ssh/sshd_config):
注意:在所有机子都需要安装ssh。
2)设置namenode的ssh为无需密码的、自动登录
[root@corenode ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair. #提示正在生成rsa密钥对
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. #提示公钥和私钥已经存放在/root/.ssh/目录
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
3c:6c:67:68:52:c6:c0:5b:f1:64:2d:29:e7:e5:93:cf root@corenode #提示key的指纹
一直按回车
完成后,默认root目录下会产生隐藏文件夹.ssh
[root@corenode ssh]# cd .ssh
复制公共密钥文件 id_rsa.pub
cp id_rsa.pub authorized_keys
改动你的 authorized_keys 文件的许可权限(根据实际情况而定)
[root@corenode ssh]# chmod 644 authorized_keys
测试:
[root@corenode ssh]# ssh localhost 或者 ssh corenode
第一次ssh会有提示信息:
The authenticity of host ‘corenode (10.64.56.76)’ can’t be established.
RSA key fingerprint is 03:e0:30:cb:6e:13:a8:70:c9:7e:cf:ff:33:2a:67:30.
Are you sure you want to continue connecting (yes/no)?
输入 yes 来继续。这会把该服务器添加到你的已知主机的列表中
发现链接成功,并且无需密码。
3)复制authorized_keys到datanode01 和datanode02 上
为了保证各节点之间可以无需密码自动登录,需要在其它节点上执行第二步操作.
将公用密钥复制到主节点上:
[root@datanode01 ssh]# scp .ssh/id_rsa.pub corenode:.ssh/datanode01_keys
[root@datanode02 ssh]# scp .ssh/id_rsa.pub corenode:.ssh/datanode02_keys
然后进行合并:
[root@corenode ssh]# cat datanoce01_keys >> authorized_keys
[root@corenode ssh]# cat datanoce02_keys >> authorized_keys
最后将合并密钥文件,复制到其它节点上:
[root@corenode ssh]# scp .ssh/authorized_keys datanode01:.ssh/
[root@corenode ssh]# scp .ssh/authorized_keys datanode02:.ssh/
各个节点之间就可以相互访问了.
这个安装完后,可以直接使用ssh命令了。
执行$ netstat -nat 查看22端口是否开启了。
测试:ssh localhost。
输入当前用户的密码,回车就ok了。说明安装成功,同时ssh登录需要密码。
(这种默认安装方式完后,默认配置文件是在/etc/ssh/目录下。sshd配置文件是:/etc/ssh/sshd_config):
注意:在所有机子都需要安装ssh。
2)设置namenode的ssh为无需密码的、自动登录
[root@corenode ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair. #提示正在生成rsa密钥对
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. #提示公钥和私钥已经存放在/root/.ssh/目录
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
3c:6c:67:68:52:c6:c0:5b:f1:64:2d:29:e7:e5:93:cf root@corenode #提示key的指纹
一直按回车
完成后,默认root目录下会产生隐藏文件夹.ssh
[root@corenode ssh]# cd .ssh
复制公共密钥文件 id_rsa.pub
cp id_rsa.pub authorized_keys
改动你的 authorized_keys 文件的许可权限(根据实际情况而定)
[root@corenode ssh]# chmod 644 authorized_keys
测试:
[root@corenode ssh]# ssh localhost 或者 ssh corenode
第一次ssh会有提示信息:
The authenticity of host ‘corenode (10.64.56.76)’ can’t be established.
RSA key fingerprint is 03:e0:30:cb:6e:13:a8:70:c9:7e:cf:ff:33:2a:67:30.
Are you sure you want to continue connecting (yes/no)?
输入 yes 来继续。这会把该服务器添加到你的已知主机的列表中
发现链接成功,并且无需密码。
3)复制authorized_keys到datanode01 和datanode02 上
为了保证各节点之间可以无需密码自动登录,需要在其它节点上执行第二步操作.
将公用密钥复制到主节点上:
[root@datanode01 ssh]# scp .ssh/id_rsa.pub corenode:.ssh/datanode01_keys
[root@datanode02 ssh]# scp .ssh/id_rsa.pub corenode:.ssh/datanode02_keys
然后进行合并:
[root@corenode ssh]# cat datanoce01_keys >> authorized_keys
[root@corenode ssh]# cat datanoce02_keys >> authorized_keys
最后将合并密钥文件,复制到其它节点上:
[root@corenode ssh]# scp .ssh/authorized_keys datanode01:.ssh/
[root@corenode ssh]# scp .ssh/authorized_keys datanode02:.ssh/
各个节点之间就可以相互访问了.