Why use SSH keys?
Why use SSH config?
Let's open your terminal or PowerShell in your computer before we start.
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.
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]
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
Congratulation!๐