schrodinger.utils.sshconfig module¶
The sshconfig module contains code to configure Passwordless SSH.
Example:
- Get the keypair to use using find_key_pair(..).
- Check the keypair is okay before local host ssh setup using check_key_pair(..).
- If the keypair is not okay, generate keypair in local system using configure_local_ssh_setup().
- Setup passwordless SSH to desired host using install_remote_pubkey(..).
from schrodinger.utils import sshconfig
(priv_file, pub_file) = sshconfig.find_key_pair()
pub_key = sshconfig.check_key_pair(priv_file, pub_file)
if not pub_key:
pub_key = sshconfig.configure_local_ssh_setup(priv_file, pub_file)
sshconfig.install_remote_pubkey("bobio", "rajagopa", "blah-blah", pub_key)
-
schrodinger.utils.sshconfig.
find_key_pair
()¶ Get the private and public key filename to use.
Returntype: tuple Returns: A tuple containing private and public key filename.
-
schrodinger.utils.sshconfig.
check_key_pair
(priv_file, pub_file)¶ Check the given private and public key file to make sure they match. For Windows, the private key file is assumed to be in ppk understandable format.
Parameters: - priv_file (string) – Private key file.
- pub_file (string) – Public key file.
Returntype: string
Returns: base64 string containing public part of the key pair, on success empty string otherwise
-
schrodinger.utils.sshconfig.
configure_local_ssh_setup
(priv_file, pub_file)¶ Set up SSH key pair on your local machine. The private key is written to the file given. For windows this will be in plink understandable format and for non-windows this will be in OpenSSH format.
And the public key is written in <priv_file without extension>.pub in OpenSSH format.
Parameters: priv_file (string) – Private key file to write.
Returntype: string
Returns: base64 string containing public part of the key pair
Raises: - OSError – if plink_keygen binary to convert OpenSSH to ppk doesn’t exist
- RuntimeError – if the command to convert OpenSSH to ppk failed
- IOError – if there was an error writing private/public key file
- SSHException – if the private key file was invalid to get the public key.
-
schrodinger.utils.sshconfig.
install_remote_pubkey
(hostname, user, password, pubkey)¶ Setup passwordless ssh to the given remote host.
Parameters: - hostname (string) – Setup passwordless ssh to this remote host.
- user (string) – Specify the user to log in as on the remote machine.
- password (string) – Password to use for logging into the remote machine.
- pubkey (string) – Public key to cache in ‘authorized_keys’ of the remote machine.
Raises: - paramiko.AuthenticationException – if the authentication failed.
- paramiko.SSHException – if there was an error connecting or establishing an SSH session.
- RuntimeError – if the command to cached public key at remote host fail or if the command to cache remote host’s fingerprint in registry fail (Windows).
-
schrodinger.utils.sshconfig.
cache_hostname_plink
(user, hostname)¶ Caches particular host name. This is intended to be run after we already have set up public key on remote host.
Parameters: - hostname (string) – name of host
- user (string) – username for remote host
-
schrodinger.utils.sshconfig.
hostname_in_registry
(hostname)¶ If hostname is in cached registry, returns True. Only relevant to call on Windows.
Parameters: hostname (str) – name of host referred to in plink Returns: bool
-
schrodinger.utils.sshconfig.
known_hostname
(hostname)¶ Checks if hostname has already been configured to use Passwordless SSH.
Parameters: hostname (str) – name of host Returns: bool