SSH 免密登录
准备工作
- ubuntu 15 桌面版操做系统
操做步聚
安装sshpass
- 可以免密码输入登录ssh
- sudo apt-get install sshpass
本机免密登录
这一部分不要放一循环体内,当然master节点,单独执行
rm -rf ~/.ssh
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
循环部分
安装远程本机ssh免密登录远程本机
- export TEMP_REMOTE_DIR=~/temp/id_dsa_dir
sshpass -p hadoop ssh s1 "rm -rf -f ~/.ssh"
sshpass -p hadoop ssh s1 "ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa"
sshpass -p hadoop ssh s1 "cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys"
安装本机ssh免密登录远程
- export TEMP_REMOTE_DIR=~/temp/id_dsa_dir
sshpass -p hadoop ssh s1 "rm -rf $TEMP_REMOTE_DIR"
sshpass -p hadoop ssh s1 "mkdir -p $TEMP_REMOTE_DIR"
sshpass -p hadoop scp -r ~/.ssh/id_dsa.pub s1:$TEMP_REMOTE_DIR
sshpass -p hadoop ssh s1 "cat ${TEMP_REMOTE_DIR}/id_dsa.pub >> ~/.ssh/authorized_keys"