您好,登錄后才能下訂單哦!
自動生成公鑰并自動寫入到特定服務器腳本
普遍賬號需開的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}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。