Package schrodinger :: Package utils :: Module sshconfig
[hide private]
[frames] | no frames]

Module sshconfig


The sshconfig module contains code to configure Passwordless SSH.

Example -
    A) Get the keypair to use using find_key_pair(..).
    B) Check the keypair is okay before local host ssh setup using
       check_key_pair(..).
    C) If the keypair is not okay, generate keypair in local system using
       configure_local_ssh_setup().
    D) 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)

Functions [hide private]
string
_get_pub_key(pub_file)
Get the public key from SSH keypair setup on your local machine.
 
_convert_ppk_openssh(ppk_file, priv_file)
Convert ppk to OpenSSH.
 
_convert_openssh_ppk(priv_file, ppk_file)
Convert OpenSSH to ppk.
bool
_grep(filename, search_string)
Grep the given search string in provided filename.
tuple
find_key_pair()
Get the private and public key filename to use.
string
check_key_pair(priv_file, pub_file)
Check the given private and public key file to make sure they match.
string
configure_local_ssh_setup(priv_file, pub_file)
Set up SSH key pair on your local machine.
 
install_remote_pubkey(hostname, user, password, pubkey)
Setup passwordless ssh to the given remote host.
 
cache_hostname_plink(user, hostname)
Caches particular host name.
 
hostname_in_registry(hostname)
If hostname is in cached registry, returns True.
Variables [hide private]
  GENERATE_KEY_BITS = 2048
  __package__ = 'schrodinger.utils'
Function Details [hide private]

_get_pub_key(pub_file)

 

Get the public key from SSH keypair setup on your local machine.

Parameters:
  • pub_file (string) - Public key file to read and get the data.
Returns: string
public key as base64 string.

_convert_ppk_openssh(ppk_file, priv_file)

 

Convert ppk to OpenSSH.

Parameters:
  • ppk_file (string) - file to convert the ppk format.
  • priv_file (string) - file to write the OpenSSH format.
Raises:
  • OSError - if plink_keygen binary to convert ppk to OpenSSH doesn't exist
  • RuntimeError - if the command to convert ppk to OpenSSH failed

_convert_openssh_ppk(priv_file, ppk_file)

 

Convert OpenSSH to ppk.

Parameters:
  • priv_file (string) - file to convert the OpenSSH format.
  • ppk_file (string) - file to write the ppk format.
Raises:
  • OSError - if plink_keygen binary to convert OpenSSH to ppk doesn't exist
  • RuntimeError - if the command to convert OpenSSH to ppk failed

_grep(filename, search_string)

 

Grep the given search string in provided filename.

Parameters:
  • filename (string) - filename to search the given pattern.
  • search_string (string) - Pattern to search in the given filename.
Returns: bool
True if search string is found. False if search string is not found or given filename doesn't exist.

find_key_pair()

 

Get the private and public key filename to use.

Returns: tuple
A tuple containing private and public key filename.

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.
Returns: string
base64 string containing public part of the key pair, on success empty string otherwise

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.
Returns: string
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.

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:
  • AuthenticationException - if the authentication failed.
  • 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).

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

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