Skip to content

Instantly share code, notes, and snippets.

@Sasha-hk
Created April 16, 2022 13:54
Show Gist options
  • Save Sasha-hk/b816ccf83959a5f63aac0b3cf16b17a0 to your computer and use it in GitHub Desktop.
Save Sasha-hk/b816ccf83959a5f63aac0b3cf16b17a0 to your computer and use it in GitHub Desktop.

SSH tutorial

SSH is - secure server shell, that allows for us to interact with remove server, for example your VPS

Generate SSH keys

The command:

ssh-keygen

The command generate pair keys public and private.

You can find the kays in your root directory in .ssh folder, eg. /home/master/.ssh

It looks like this:

cd /home/master/.ssh
ls -la

drw-------  2 master master 4096 Feb  4 15:06 .
drwx------ 10 master master 4096 Apr 16 16:44 ..
-rw-------  1 master master 2602 Feb  1 09:38 id_rsa
-rw-r--r--  1 master master  567 Feb  1 09:38 id_rsa.pub

id_rsa is your private key, the key must not fall into the wrong hands.

id_rsa.pub is public key, any one can take the key, and use to authorize you when you will try to connect to remote machine.

Send public key to the server

The command:

ssh-copy-id username@ip

In completed variant it can looks like:

ssh-copy-id [email protected]

After executing the command, you need to enter the password for the user you specified in the command above.

On the server

To get public key that can connect to the server you need to go to the .ssh directory, and run the following:

ls -la

drw-------  2 root root 4096 Feb  4 15:06 .
drwx------ 10 root root 4096 Apr 16 16:44 ..
-rw-------  1 root root 5499 Feb  4 15:26 authorized_keys

The file authorized_keys file stores all the public keys that can log-in to the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment