批量操作SSH账户信任
2015-12-12 00:25
489 查看
#!/bin/bash
auto_ssh_key () {
expect -c "
set timeout -1;
spawn ssh-copy-id -i $path/.ssh/id_rsa $1;
expect {
*yes/no* {
send -- yes\r
expect *assword*
send -- $2\r;
expect {
*denied* {exit 2;}
eof
}
}
*assword* {
send -- $2\r;
expect {
*denied* {exit 2;}
eof
}
}
eof
}
"
}
echo '
-------------------- Directions for use --------------------
| Internal IP using examples: |
| please input port: 10 15 29 21 21 |
| External use IP example: |
| please input port: 8.8.8.8 google.xxx.com |
| |
| please input port: |
| A null value as the default port 22 |
| |
| please input username: |
| A null value as the current user |
------------------------------------------------------------
'
# 获取用户家目录路径path=`awk NR==$(echo $(awk -F ':' '{print $1}' /etc/passwd | grep -xn $(whoami)) | awk -F ':' '{print $1}') /etc/passwd | awk -F ':' '{print $6}'`
read -p "please input ip:" ip
read -p "please input port:" port
read -p "please input username:" username
read -s -p "please input password:" password
# 判断是否指定端口, 默认为22
if [ -z $port ];then
port='22'
fi
# 判断是否指定用户名, 默认为当前账号
if [ -z $username ];then
username=$(whoami)
fi
# 检测输入的IP是内部还是外部机器
data_size=`echo $ip | awk -F " " '{print $1}'|wc -L`
for i in $ip
do
if [ $data_size -lt 4 ];then
auto_ssh_key '"-p '$port' '$username'@10.0.0.'$i'"' $password
else
auto_ssh_key '"-p '$port' '$username'@'$i'"' $password
fi
done
本文出自 “、矿泉水” 博客,请务必保留此出处http://guwenqiang.blog.51cto.com/5462040/1722230
auto_ssh_key () {
expect -c "
set timeout -1;
spawn ssh-copy-id -i $path/.ssh/id_rsa $1;
expect {
*yes/no* {
send -- yes\r
expect *assword*
send -- $2\r;
expect {
*denied* {exit 2;}
eof
}
}
*assword* {
send -- $2\r;
expect {
*denied* {exit 2;}
eof
}
}
eof
}
"
}
echo '
-------------------- Directions for use --------------------
| Internal IP using examples: |
| please input port: 10 15 29 21 21 |
| External use IP example: |
| please input port: 8.8.8.8 google.xxx.com |
| |
| please input port: |
| A null value as the default port 22 |
| |
| please input username: |
| A null value as the current user |
------------------------------------------------------------
'
# 获取用户家目录路径path=`awk NR==$(echo $(awk -F ':' '{print $1}' /etc/passwd | grep -xn $(whoami)) | awk -F ':' '{print $1}') /etc/passwd | awk -F ':' '{print $6}'`
read -p "please input ip:" ip
read -p "please input port:" port
read -p "please input username:" username
read -s -p "please input password:" password
# 判断是否指定端口, 默认为22
if [ -z $port ];then
port='22'
fi
# 判断是否指定用户名, 默认为当前账号
if [ -z $username ];then
username=$(whoami)
fi
# 检测输入的IP是内部还是外部机器
data_size=`echo $ip | awk -F " " '{print $1}'|wc -L`
for i in $ip
do
if [ $data_size -lt 4 ];then
auto_ssh_key '"-p '$port' '$username'@10.0.0.'$i'"' $password
else
auto_ssh_key '"-p '$port' '$username'@'$i'"' $password
fi
done
本文出自 “、矿泉水” 博客,请务必保留此出处http://guwenqiang.blog.51cto.com/5462040/1722230
相关文章推荐
- bzoj1711【Usaco2007 Open】Dingin 吃饭
- RecycleView套用demo
- using an empty LLDB target which can cause slow memory reads from remote devices.
- Oracle ERP Profile
- 转: 什么是REST?
- 【linux】关于分析系统问题的前几分钟
- Sublime Text3
- Linux 下的Core Dump
- ubuntu14.04 桌面菜单栏和任务栏不见了
- 如何修改系统UISearchBar的样式
- 简单易懂的命名空间及use的使用
- poj 2392 Space Elevator 排序(贪心)+多重背包 仍然很水 ★★
- Android异步任务处理之AsyncTask异步操作类的使用方法1(不含onCancelled部分)
- IOS--UITableViewCell上的按钮点击事件处理
- 实战c++中的string系列--string的遍历(使用下标还是iterator)
- 实战c++中的string系列--string的遍历(使用下标还是iterator)
- 搭建iOS框架
- GNU C 的一大特色就是__attribute__ 机制
- Valid Parentheses
- js----显示当前系统时间