Categories
Linux

Connect via SSH to your Linux Server

A straight forward instruction how to configure a ssh connection to your Linux server with your bash terminal.

You have a Linux server and would like to access it without typing in your password every time? I widely used method is to use a ssh key pair, containing of a private and public key. Here is a straight forward instruction how to configure a ssh connection to your Linux server with your bash terminal.

Create a SSH key

Go to your folder ~/.ssh/

cd ~/.ssh

and create a SSH key with the command

ssh-keygen

you will be asked to specify a file name. By default the name id_rsa will be used, if you don’t have already created other keys you can just hit enter. Otherwise enter a new name.

Next you will be asked for a passphrase, which encrypts your key and ensures additional security. If you leave it empty the key won’t be encrypted.

Retype your passphrase or leave it empty and hit enter again.

Your key is created.

Two files got created one with the ending .pub and one with just your chosen file name. The .pub file is your public key. You have to upload it on your server. The default file is your private key, keep it secret!

Upload the public key

Now you have to upload your public key to your server. The easiest way is to use ssh-copy-id, it is installed by default on nearly all Linux machines. Keep in mind that uploading your public key with ssh-copy-id is only possible if your server has activated password login. However, you can disable password login after uploading your public key. Go and copy your server IP address, you will need it and type:

ssh-copy-id <username>@<server_ip>

In case you have created your ssh key with a different name, you have to specify the path by using the option -i

ssh-copy-id -i ~/<path_to_your_public_key> <username>@<server_ip>

Establish a connection

Now you should be able to login via ssh into your server, test it with the command

ssh <username>@<server>

Leave a Reply

Your email address will not be published. Required fields are marked *