Manage client ssh components
Note
This module requires the use of MD5 hashing. Certain security audits may not permit the use of MD5. For those cases, this module should be disabled or removed.
Return the authorized keys for users
CLI Example:
salt '*' ssh.auth_keys salt '*' ssh.auth_keys root salt '*' ssh.auth_keys user=root salt '*' ssh.auth_keys user="[user1, user2]"
Check to see if a key needs updating, returns "update", "add" or "exists"
CLI Example:
salt '*' ssh.check_key <user> <key> <enc> <comment> <options>
Check a keyfile from a source destination against the local keys and return the keys to change
CLI Example:
salt '*' ssh.check_key_file root salt://ssh/keyfile
Check the record in known_hosts file, either by its value or by fingerprint (it's enough to set up either key or fingerprint, you don't need to set up both).
If provided key or fingerprint doesn't match with stored value, return "update", if no value is found for a given host, return "add", otherwise return "exists".
If neither key, nor fingerprint is defined, then additional validation is not performed.
CLI Example:
salt '*' ssh.check_known_host <user> <hostname> key='AAAA...FAaQ=='
Deprecated since version 2018.3.0: Use ssh.get_known_host_entries
instead.
Return information about known host from the configfile, if any. If there is no such key, return None.
CLI Example:
salt '*' ssh.get_known_host <user> <hostname>
New in version 2018.3.0.
Return information about known host entries from the configfile, if any. If there are no entries for a matching hostname, return None.
CLI Example:
salt '*' ssh.get_known_host_entries <user> <hostname>
Hash all the hostnames in the known hosts file.
New in version 2014.7.0.
CLI Example:
salt '*' ssh.hash_known_hosts
Return the minion's host keys
CLI Example:
salt '*' ssh.host_keys salt '*' ssh.host_keys keydir=/etc/ssh salt '*' ssh.host_keys keydir=/etc/ssh private=False salt '*' ssh.host_keys keydir=/etc/ssh certs=False
New in version 2015.8.7.
Function to determine whether or not a private key is encrypted with a passphrase.
Checks key for a Proc-Type
header with ENCRYPTED
in the value. If found, returns True
, otherwise returns False
.
CLI Example:
salt '*' ssh.key_is_encrypted /root/id_rsa
Retrieve information about host public key from remote server
Deprecated since version 2018.3.0: Use ssh.recv_known_host_entries
instead.
Set the timeout for connection attempts. If timeout
seconds have elapsed since a connection was initiated to a host or since the last time anything was read from that host, then the connection is closed and the host in question considered unavailable. Default is 5 seconds.
New in version 2016.3.0.
The fingerprint hash type that the public key fingerprints were originally hashed with. This defaults to sha256
if not specified.
New in version 2016.11.4.
Changed in version 2017.7.0:: default changed from md5
to sha256
CLI Example:
salt '*' ssh.recv_known_host <hostname> enc=<enc> port=<port>
New in version 2018.3.0.
Retrieve information about host public keys from remote server
timeout
seconds have elapsed since a connection was initiated to a host or since the last time anything was read from that host, then the connection is closed and the host in question considered unavailable. Default is 5 seconds.The fingerprint hash type that the public key fingerprints were originally hashed with. This defaults to sha256
if not specified.
New in version 2016.11.4.
Changed in version 2017.7.0:: default changed from md5
to sha256
CLI Example:
salt '*' ssh.recv_known_host_entries <hostname> enc=<enc> port=<port>
Remove an authorized key from the specified user's authorized key file
CLI Example:
salt '*' ssh.rm_auth_key <user> <key>
Remove an authorized key from the specified user's authorized key file, using a file as source
CLI Example:
salt '*' ssh.rm_auth_key_from_file <user> salt://ssh_keys/<user>.id_rsa.pub
Remove all keys belonging to hostname from a known_hosts file.
CLI Example:
salt '*' ssh.rm_known_host <user> <hostname>
Add a key to the authorized_keys file. The "key" parameter must only be the string of text that is the encoded key. If the key begins with "ssh-rsa" or ends with user@host, remove those from the key before passing it to this function.
CLI Example:
salt '*' ssh.set_auth_key <user> '<key>' enc='dsa'
Add a key to the authorized_keys file, using a file as the source.
CLI Example:
salt '*' ssh.set_auth_key_from_file <user> salt://ssh_keys/<user>.id_rsa.pub
Download SSH public key from remote host "hostname", optionally validate its fingerprint against "fingerprint" variable and save the record in the known_hosts file.
If such a record does already exists in there, do nothing.
Set the timeout for connection attempts. If timeout
seconds have elapsed since a connection was initiated to a host or since the last time anything was read from that host, then the connection is closed and the host in question considered unavailable. Default is 5 seconds.
New in version 2016.3.0.
The public key fingerprint hash type that the public key fingerprint was originally hashed with. This defaults to sha256
if not specified.
New in version 2016.11.4.
Changed in version 2017.7.0:: default changed from md5
to sha256
CLI Example:
salt '*' ssh.set_known_host <user> fingerprint='xx:xx:..:xx' enc='ssh-rsa' config='.ssh/known_hosts'
Return the user's ssh keys on the minion
New in version 2014.7.0.
CLI Example:
salt '*' ssh.user_keys salt '*' ssh.user_keys user=user1 salt '*' ssh.user_keys user=user1 pubfile=/home/user1/.ssh/id_rsa.pub prvfile=/home/user1/.ssh/id_rsa salt '*' ssh.user_keys user=user1 prvfile=False salt '*' ssh.user_keys user="['user1','user2'] pubfile=id_rsa.pub prvfile=id_rsa
As you can see you can tell Salt not to read from the user's private (or public) key file by setting the file path to False
. This can be useful to prevent Salt from publishing private data via Salt Mine or others.
© 2019 SaltStack.
Licensed under the Apache License, Version 2.0.
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.ssh.html