Applied SSHs: Part 1
SSH keys are extremely useful when you are establishing access to a remote server, which could well be a GPU cluster or cloud server running on AWS or Azure. Here are some easy to understand steps that can help you conveniently access your servers.
Step 1: Generate RSA folder
If not already done, create a .ssh
file in $HOME
(equivalently ~
). Give it permission using chmod
.
mkdir -p ~/.ssh
chmod 0700 ~/.ssh
Step 2: Generate RSA keys. Public + Private
ssh-keygen -t rsa
Simple. There will be id_rsa
and id_rsa.pub
appearing in ~/.ssh
now.
Step 3: Remote access
Your remote server almost certainly already has ~/.ssh
all set up. If not, repeat steps 1 and 2 on the remote server.
If you don’t see authorized_keys
in the remote server, you can either make one and simply replace it with your local public key
scp ~/.ssh/id_rsa.pub username@server:~/.ssh/authorized_keys
or if there is one already, we append our public key to authorized_keys
.
cat ~/.ssh/id_rsa.pub | ssh username@server "cat >> .ssh/authorized_keys"
Step 4 (optional): Password-free ssh
Ok so you’re tired of typing in your password all the time and you just want a 1-liner.
Go to ~/.ssh
and see if there is a config
file. If not, make one. The syntax is as follows:
config
Host INPUT_YOUR_PREFERRED_ALIAS
Hostname INPUT_HOSTNAME
user INPUTYOURUSERNAME
add this information in. Then do
ssh INPUT_YOUR_PREFERRED_ALIAS
and bingo! :)
References:
- https://www.cyberciti.biz/faq/how-to-set-up-ssh-keys-on-linux-unix/