SSH Key and Config

Why use SSH keys?

  • Login to the remote server without entering a password

Why use SSH config?

  • Simplify the SSH process with shorter commands

Let's open your terminal or PowerShell in your computer before we start.

1. Create SSH key

Use the following command to create SSH key.

ssh-keygen

After running the command, you'll see the following output:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/cial1/.ssh/id_rsa):

Press Enter to use the default path.

Enter passphrase (empty for no passphrase): 

Press Enter again to ignore passphrase.

Enter same passphrase again:

Press Enter again to confirm ignoring passphrase.

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More โ†’

(The SSH Key generated by each individual is unique.)

2. Add public key to remote server

First, we need to enter .ssh directory

cd ~/.ssh

If you use ls command, you will see id_rsa.pub, that is your SSH public key.

Use the following command to copy your SSH public key to the remote server.

scp id_rsa.pub [username]@[ip address]:~/.ssh/authorized_keys

Make sure to replace [username] with your actual username and replace [ip address] with the server's actual ip address.

For example :

scp id_rsa.pub F74114710@140.116.246.48:~/.ssh/authorized_keys

After running this command, you may need to enter your password for server authentication.

Finally, you can SSH to the server without typing a password.๐ŸŽ‰

ssh [username]@[ip address]

3. Setup SSH config

Create a file named config at ~/.ssh/config

vim ~/.ssh/config

If your computer runs on Windows and does not have Vim installed, you can use the following commands(in PowerShell):

New-Item ~/.ssh/config
~/.ssh/config

Then choose the editor you like.

Paste the following text inside the config file

 HOST            pd1
 Hostname        [ip address]
 User            [username]

Make sure to replace [ip address] with the server's actual ip address and replace [username] with your actual username.

For example:

 HOST            pd1
 Hostname        140.116.246.48
 User            F74114710

Remember to save the file.


Now, you can use the following command to connect to the server

ssh pd1

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More โ†’


Congratulation!๐ŸŽ‰