This Python script automates SSH key creation and configuration for a remote server. It performs the following:
- Checks if you are on a Unix-like system (it will not run on Windows unless under WSL).
- Verifies that the remote server is reachable (e.g., ensure you are on the correct network or connected via a VPN).
- Creates a new SSH key and passphrase for connecting to the server.
- Optionally backs up your existing
~/.sshdirectory. - Updates your
~/.ssh/known_hostsfile with the server's keys. - Copies the newly created key to the remote server via
ssh-copy-id. - Updates your local
~/.ssh/configfile for easy login.
python3 ssh_setup.py <username> [OPTIONS]-q, --quiet
Suppress most output.
-w, --wincpy
Copy the generated SSH key to a Windows partition’s ~.ssh folder (for WSL users).
--disablebackup
Disable creation of a backup for your ~/.ssh directory.
python3 ssh_setup.py alice.smithAfter running the script successfully, you can connect to the server with either:
ssh alice.smith@<your-server-domain>or
ssh <your-config-alias>-
Python 3 (the script has been tested on 3.7+).
-
OpenSSH client (for ssh, ssh-keygen, ssh-copy-id, ssh-keyscan, etc.).
-
WSL (if you plan to use -w/--wincpy on Windows).
-
Ensure you are on the correct private network or connected via VPN to reach the remote server.
-
The script exits if not running on a supported OS (os.name must be posix).
-
The default key type created is ed25519 with a 4096-bit key size.