saltstack之salt-ssh用法


一、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

  

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM