一、salt-ssh
1、salt-ssh安裝
yum install s/salt-ssh -y
2、配置文件
參考:https://docs.saltstack.com/en/latest/topics/ssh/index.html
cd /etc/salt/
[root@salt salt]# vi roster # Sample salt-ssh config file #web1: # host: 192.168.42.1 # The IP addr or DNS hostname # user: fred # Remote executions will be executed as user fred # passwd: foobarbaz # The password to use for login, if omitted, keys are used # sudo: True # Whether to sudo to root, not enabled by default #web2: # host: 192.168.42.2 linux-node1: host: 192.168.56.42 user: root passwd: 1qaz@WSX prod: 22
測試,參數 -i ,如果詢問密碼就加-i,直接幫你確認,-i = yes
[root@salt salt]# salt-ssh '*' test.ping linux-node1: True #確認yes [root@salt salt]# salt-ssh '*' test.ping -i linux-node1: True
#配置不提示你輸入yes
[root@salt .ssh]# pwd /root/.ssh [root@salt .ssh]# ll total 16 -rw-r--r-- 1 root root 25 Jun 24 11:22 config -rw------- 1 root root 1675 Jun 24 06:37 id_rsa -rw-r--r-- 1 root root 391 Jun 24 06:37 id_rsa.pub -rw-r--r-- 1 root root 187 Jun 24 06:39 known_hosts
#寫入下面配置文件和參數,就不會提示你輸入yes,進行確認。 [root@salt .ssh]# cat config StrictHostKeyChecking no
#普通用戶
web1: host: 192.168.42.1 # The IP addr or DNS hostname user: fred # Remote executions will be executed as user fred passwd: foobarbaz # The password to use for login, if omitted, keys are used sudo: True # Whether to sudo to root, not enabled by default
#查看時間
[root@salt salt]# salt-ssh '*' -r "uptime" linux-node1: ---------- retcode: 0 stderr: stdout: root@192.168.56.42's password: 11:18:39 up 4:54, 2 users, load average: 0.00, 0.01, 0.05
#w
[root@salt .ssh]# salt-ssh '*' -r "w" linux-node1: ---------- retcode: 0 stderr: stdout: root@192.168.56.42's password: 11:24:33 up 5:00, 2 users, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 06:25 4:52m 0.20s 0.20s -bash root pts/1 192.168.56.1 11:05 18:37 0.00s 0.00s -bash