Skip to content

Instantly share code, notes, and snippets.

@mauricios
Last active November 17, 2020 15:47
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 mauricios/251f9f88074e7d9dac16e9fbcb8ff161 to your computer and use it in GitHub Desktop.
Save mauricios/251f9f88074e7d9dac16e9fbcb8ff161 to your computer and use it in GitHub Desktop.
Generate SSH key pair

Generate SSH key pair

Use RSA encryption with 4096 bits

ssh-keygen -t rsa -b 4096 -C "my_email@mydomain.com" -f ~/.ssh/myserver.key -P ""

The command above will generate two files, the private key ~/.ssh/myserver.key and the public key ~/.ssh/myserver.key.pub.

Now you can use th SSH key pair to access machines via SSH

Configure SSH config

To connect via SSH without a password using a simplified command you can use the following instrucctions:

Edit the file ~/.ssh/config and add the following:

Host myserver.com
    HostName myserver.com
    User myuser
    IdentityFile ~/.ssh/myserver.key

Now you can use any SSH connection command passwordless:

ssh myserver.com

You can also configre the remote Git server in your local repo using the SSH configuration, e.g. git@myserver.com

Next steps

  • Upload the public key to the machine in the ~/.ssh/authorized_keys file or upload to the Git service
  • Keep you private key secure in your local machine.
  • Use you private key to connect to the server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment