Skip to content

Instantly share code, notes, and snippets.

@nahiyan
Created October 13, 2021 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahiyan/914cc7c6227882c7cf04f85ac95b25f3 to your computer and use it in GitHub Desktop.
Save nahiyan/914cc7c6227882c7cf04f85ac95b25f3 to your computer and use it in GitHub Desktop.
Automatically create SSH keys in Linux
import subprocess
import sys
import os
# take email address as an argument
if len(sys.argv) == 4:
name = sys.argv[1]
email_address = sys.argv[2]
linux_username = sys.argv[3]
key_file_path = "/home/" + linux_username + "/.ssh/" + name
subprocess.run(["ssh-keygen", "-t", "rsa", "-b", "4096",
"-C", email_address, "-f", key_file_path, "-N", ""])
subprocess.run(["ssh-add", key_file_path])
os.system("cat " + key_file_path +
".pub | xclip -selection clipboard")
print("Key copied to clipboard!")
else:
print("Please provide a name (one word), email address, and the Linux username.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment