自动生成公钥并自动写入到特定服务器脚本
2017-05-04 16:43
211 查看
自动生成公钥并自动写入到特定服务器脚本
普遍账号需开的sudo权限
zhi.yang ALL=(ALL:ALL)NOPASSWD:/usr/bin/tee -a /root/.ssh/authorized_keys,/bin/mkdir /log/*
# expect/usr/local/bin/sshkey.exp 10.0.0.3 shaa01 zhi.yang xxxxx
#!/usr/bin/expect
set ip [lindex $argv 0]
set hostname [lindex $argv 1]
set user [lindex $argv 2]
set password [lindex $argv 3]
spawn ssh-keygen
expect {
"*id_rsa):" {send "\r";exp_continue}
"*passphrase):" {send "\r";exp_continue}
"*again:" {send "\r"}
}
expect eof
spawn scp -r /root/.ssh/id_rsa.pub $user@$ip:/tmp/
expect {
"*(yes/no)*" {send "yes\r";exp_continue}
"*Password:" {send "$password\r"}
}
expect eof
spawn ssh $user@$ip
expect {
"*Password:" {send "$password\r"}
}
expect eof
expect "$*"
send "sudo mkdir /log/$hostname\r"
send "cat /tmp/id_rsa.pub | sudo tee -a /root/.ssh/authorized_keys\r"
send "rm -rf /tmp/id_rsa.pub\r"
send "exit\r"
expect eof
exec sh -c {/bin/sh /usr/local/bin/diskG9.sh}
普遍账号需开的sudo权限
zhi.yang ALL=(ALL:ALL)NOPASSWD:/usr/bin/tee -a /root/.ssh/authorized_keys,/bin/mkdir /log/*
# expect/usr/local/bin/sshkey.exp 10.0.0.3 shaa01 zhi.yang xxxxx
#!/usr/bin/expect
set ip [lindex $argv 0]
set hostname [lindex $argv 1]
set user [lindex $argv 2]
set password [lindex $argv 3]
spawn ssh-keygen
expect {
"*id_rsa):" {send "\r";exp_continue}
"*passphrase):" {send "\r";exp_continue}
"*again:" {send "\r"}
}
expect eof
spawn scp -r /root/.ssh/id_rsa.pub $user@$ip:/tmp/
expect {
"*(yes/no)*" {send "yes\r";exp_continue}
"*Password:" {send "$password\r"}
}
expect eof
spawn ssh $user@$ip
expect {
"*Password:" {send "$password\r"}
}
expect eof
expect "$*"
send "sudo mkdir /log/$hostname\r"
send "cat /tmp/id_rsa.pub | sudo tee -a /root/.ssh/authorized_keys\r"
send "rm -rf /tmp/id_rsa.pub\r"
send "exit\r"
expect eof
exec sh -c {/bin/sh /usr/local/bin/diskG9.sh}
相关文章推荐
- centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课
- Nconf点生成Nagios配置文件的同时自动执行脚本
- Shell脚本实现自动输入密码登录服务器
- 自制脚本语言(4) 自动生成的词法分析器
- 批量添加ssh认证公钥的脚本,有利于大批量管理服务器哦。
- 自动生成Insert数据的SQL脚本
- PowerDesigner,根据name自动生成commnet的脚本
- 自动生成批量执行SQL脚本的批处理
- 自动生成运行 robotium 的 bat 脚本--二版
- shell脚本实现多台服务器自动巡检--可参考学习
- 【Loadrunner报错】-VUGen生成脚本自动保存时,未到100%闪退
- Linux VPS/服务器 网站及数据库自动本地备份并FTP上传备份脚本
- 自动生成Insert数据的SQL脚本
- 前端资源多个产品整站一键打包&包版本管理(四)—— js&css文件文件打包并生成哈希后缀,自动写入路径、解决资源缓存问题。
- 智能监测自动重启Apache服务器的Shell脚本
- 全面解析Unity3D自动生成的脚本工程文件
- 编写服务器控件时,向页面写入脚本的方法
- crontab scp 无法自动执行,公钥已经生成,手动可执行scp
- 传奇自动刷怪脚本,节省服务器资源
- SQL Server镜像自动生成脚本