Usernames and passwords work for a small home environment, but if you’re handling multiple VM’s (or if you want to seamlessly code in an IDE like VS Code and push your changes to GitHub) you need to be able to create and manage multiple SSH keys on your system.

There are good posts online about creating an SSH key to use for SSH’ing into a remote machine, but it starts to get a slightly more complicated when trying to handle multiple SSH keys as you have to give each one a unique name.

Creating SSH keys for accessing remote machines/ VM’s

Creating a single SSH key for accessing a remote machine is straightforward, but we want to be able to create and use multiple different SSH keys. That requires us to name them uniquely. I will go through making two different SSH keys for two different remote machines.

Change your directory and create the SSH key:

Copy to Clipboard

When it ask’s where to save the key, you want to save it in your .ssh directory. If you wanted to save it as the default id_ed25519 file, that would work for one machine, but if you want to use multiple keys, you need to give it a unique name

For example (if my user was named jonezy) I would enter

Copy to Clipboard

Remote 1 can be any identifier you want to use for the remote machine

You can add a password or if you would rather not you can just press Enter twice for no password

Add SSH key to the ssh-agent

Start the ssh agent in the background

Copy to Clipboard

Now you want to edit the config file. If you don’t have one yet, don’t worry, this will create it.

Copy to Clipboard

Add the following to your config file:

Copy to Clipboard

Save and quit by typing ESC followed by :wq! and Enter

You may need to comment out line 4 by inserting a # at the start of the line. I find on some machines I need that line and on others I don’t. Run the next command as is and if you get an error about line 4 go ahead and comment it out.

Send the generated public key to your remote1 machine

Copy to Clipboard

Test

Now attempt to ssh into your remote machine. If it doesn’t ask you for a password, it worked.

Disable password based authentication

Once SSH’d into your remote machine, it is best practice to disable password ssh authentication.

Copy to Clipboard

Change PasswordAuthentication from yes to no

Restart ssh

Copy to Clipboard

To do this for a second machine, repeat the steps above but change the filename of the ssh key and ssh-copy the public key to the second remote machine.

Creating SSH keys for using GitHub with VS Code

This is assuming you already have git installed. If you don’t, you can install it. This is assuming you already have git installed. If you don’t, you can install it. run sudo yum install git if on Red Hat or sudo apt-get install git if on Debian. If you have a mac, git should be installed by default when you install xcode.

Redhat:

Copy to Clipboard

Debian:

Copy to Clipboard

Configure basic info

Copy to Clipboard

Generate SSH key

Copy to Clipboard

Name it something like

Copy to Clipboard

Enter twice to not set a password

Add SSH key to SSH Agent

Copy to Clipboard
Copy to Clipboard

ESC and :wq! to save

You may need to comment out line 4 by inserting a # at the start of the line. I find on some machines I need that line and on others I don’t. Run the next command as is and if you get an error about line 4 go ahead and comment it out.

Now run:

Copy to Clipboard

Add public key to Github

On your machine where you created the SSH key

Copy to Clipboard

Copy the output to your clipboard

Navigate to Github GPG and SSH Keys

Create a new SSH key, give it a descriptive name, and paste the contents from your clipboard as the key

Test

Copy to Clipboard

VSCode

You should now be able to use github in VSCode or your IDE of your choice. If you decide to use Remote SSH in VSCode, repeat the steps above when SSH’d into the remote machine to connect to your github on the remote machine.

  • If you want to access your home lab remotely, your […]

    Continue reading
  • If you want to access your home lab remotely, your […]

    Continue reading

Leave A Comment