Skip to main content

Automatic generation of SSH keys for VM

Project description

py-vmsshgen

Automatic generation of SSH keys for VM.

Why?

I got tired of provisioning SSH keys manually between hundreds of VMs that I had to use.

How to use?

The script generates OpenSSH keypair and pushes public key to VM using existing SSH connection that can be protected by password (or some another SSH key). The private key on client machine (that executes this application) automatically goes to ~/.ssh/{name}.pem + reference to it is appended to ~/.ssh/config for automatic pickup by SSH client configuration.

Supported parameters for key generation - https://asyncssh.readthedocs.io/en/latest/api.html#asyncssh.generate_private_key
Supported parameters for private key export - https://asyncssh.readthedocs.io/en/latest/api.html#asyncssh.SSHKey.export_private_key

Default settings:

  • Algo for generation - ssh-ed25519
  • No passphrase
  • Output private key with cipher AES256 with SHA256 hashing and 128 rounds of bcrypt.

You can install it using pip
pip install vmsshgen

All actions are done interactively in terminal:

usage: vmsshgen [-h] [-n N] [-a ALGO] [-ks KEY_SIZE] [-e EXPONENT] [-p PASSPHRASE] [-c CIPHER] [-r ROUNDS] [-hn HASH_NAME] host {password,privatekey} username pf

positional arguments:
  host                  VM hostname:port (example localhost:22)
  {password,privatekey}
                        login type
  username              VM username
  pf                    Password file location

optional arguments:
  -h, --help            show this help message and exit
  -n N, --name N        name for public/private key
  -a ALGO, --algorithm ALGO
                        algorithm for keypair (default is ssh-ed25519)
  -ks KEY_SIZE, --key-size KEY_SIZE
                        key size (only for RSA)
  -e EXPONENT, --exponent EXPONENT
                        exponent (only for RSA)
  -p PASSPHRASE, --passphrase PASSPHRASE
                        passphrase for OpenSSH key (default is None)
  -c CIPHER, --cipher CIPHER
                        cipher for OpenSSH key (default is aes256)
  -r ROUNDS, --rounds ROUNDS
                        rounds for OpenSSH key (default is 128)
  -hn HASH_NAME, --hash-name HASH_NAME
                        hash name for OpenSSH key (default is sha256)

Example with password file on linuxserver.io with password password stored in file named pf:
vmsshgen -n test localhost:2222 password linuxserver.io pf

Of course, if you want to supply password right inside of same commandline statement, there's an option using FIFO pipe:
vmsshgen -n test localhost:2222 password linuxserver.io <(echo 'password')

(Honestly, if you decided to go with this option, I suggest to ensure that history for current shell is disabled or you enter space in front of command to avoid leaking password in history)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vmsshgen-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

vmsshgen-1.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file vmsshgen-1.0.0.tar.gz.

File metadata

  • Download URL: vmsshgen-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for vmsshgen-1.0.0.tar.gz
Algorithm Hash digest
SHA256 97b42e1c1f1299c1c2605d28b4d79ac8a1b86aa848984d7f40305c09abbcf9f4
MD5 99f3ea48fe3129212998c76f87adc1a7
BLAKE2b-256 8fec3bf6aaef61fabfb609e140bcb39be0e7457b4b28f25a91b8795f92ec7be2

See more details on using hashes here.

File details

Details for the file vmsshgen-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: vmsshgen-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for vmsshgen-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01257a327ed80add213919cee67c6e383eef06e2e7e018375e760631b1931bfc
MD5 f8badfe1a16fdf680fef2fc9475684fe
BLAKE2b-256 f9205bc7b8a89470c800691b053b616fc8199a5bb4f518d1d39be49d00da137f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page