[iyunv@leigaofeng001-3zmwu .ssh]# ssh-keygen -t rsa -C "abc@163.com"
Generating public/private rsa key pair.
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.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ac:bb:48:50:1b:17:9a:25:73:1d:ff:5b:e5:e5:a8:ec abc@163.com
[iyunv@leigaofeng001-3zmwu .ssh]#
[iyunv@leigaofeng001-3zmwu .ssh]# ./sshkey.sh
spawn ssh-keygen -t rsa -C abc@123.com
Generating public/private rsa key pair.
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.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
84:cf:2c:24:aa:3a:eb:03:ef:73:36:3f:75:60:80:db abc@123.com
[iyunv@leigaofeng001-3zmwu .ssh]#
主控机批量执行,先将以上脚本copy到主控机的salt管理目录:/srv/salt/script
然后执行以下命令:
[iyunv@mobile-saltstack-mxmbe script]# salt 'staging-all-in-one-10.199*' cmd.script salt://script/sshkey.sh
staging-all-in-one-10.199.169.51:
----------
pid:
1398
retcode:
1
stderr:
send: spawn id exp5 not open
while executing
"send "\r""
invoked from within
"if { $expect_out(0,string) == "Overwrite" } {
send "y\r"
expect "*Enter passphrase*"
send "\r"
expect "*Enter same passphrase again*"
s..."
(file "/tmp/tmpRBilfX.sh" line 7)
stdout:
spawn ssh-keygen -t rsa -C gaofeng.lei@vipshop.com
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
23:ad:8f:25:12:08:e0:a8:86:c9:0d:d0:09:fc:65:38 gaofeng.lei@vipshop.com
验证是否远程执行成功: