How to work with SSH?

Giteqa

Nowadays, remote work is the norm for many companies, for example, in 2021, 16% of all global companies work completely remotely. Why is this happening? Well, firstly, the pandemic and people are afraid for their health, secondly, working from home increases the productivity of employees, thirdly, the risk of an employee leaving the company decreases, and most importantly, the balance between work and personal life improves for employees.

However, remote work provides access to the workplace remotely, which means that your system administrator must configure everything in great detail and avoid mistakes, otherwise your company's data may be stolen. It is in this case that people use SSH keys instead of the usual password to access the remote server.
How do I add an SSH key to the server? How to work remotely using SSH? And why is it needed at all? We will deal with these issues in this article.

SSH key

SSH is a protocol for remote OS management, if you do not want to enter a password every time you connect to the server, then you can use the SSH key.

Connecting with this key to the server increases security and prevents data leakage, but even such a key is not completely secure. In order to completely secure your data and not be afraid that an attacker will get on your server, you need to change the connection port from the standard one to another.

The standard port for connecting via ssh key is 22.

LINUX

How to connect to the server via SSH key?

In order for you to be able to give your employees access to their accounts from anywhere, you need to initially install an SSH server. To do this, enter

sudo apt install openssh-server

After entering this command, you need to wait for the server installation

After that, you can connect to your server by simply using the command line, for example by typing: ssh [email protected]

Where CD is the user name, and after entering the user name, you must enter the IP address.

Each time you log in with this command, you will need to enter the password from the account, and to avoid this, you need to create a private SSH key.
If you need to create a private key to access the server, this is done with the following command:

ssh-keygen –t rsa

This command allows you to create a key

Which to save the key – The key storage location, press enter to save it in the default directory
Enter passphrase - Create a code word, press enter to skip.

After creating the key, it must be added to the server, and for this we enter the following commands in the terminal:
- thanks to this command, you can output the created key, it will be written in the form of ssh-rsa QsdaErzsadAW

Next, go to the directory. ssh/ using the – cd ~/.ssh command/

After entering this folder, enter the nano authorized_keys command – this command allows you to edit the file. As soon as we have entered these commands, we enter the key we created earlier (which we learned thanks to Cat ~/.ssh/id_rsa.pub) and save it by pressing ctrl + o, then close the editor with ctrl + x.

After adding it, you may need to confirm the action and it can be confirmed by entering the letter Y.
After you have created this SSH key and added it, you have the opportunity to connect to the server without a password, since this key will be private, and it will be available only to you.

Windows

To connect to a remote work server via an SSH key, it is best to use the PUTTY program. This program is completely free and allows you to connect to servers with the SSH extension installed.

To get started, download the program from the official website - https://www.putty.org/
Next, install the program and turn it on.

When installing the program, additional programs are installed that will help you create a private SSH key for permanent access to the site without entering a password. (PuttyGen)

After enabling the program, you will need to enter the host name or its IP address.

If you entered everything correctly, then the administrator console will open next, where you will need to enter your username and password to access your account.

When you enter the login details, you will already have access to the administrator console and then you can do all the necessary work.

To generate a key, you will need to use PuTTYgen.

Open the program and click "Generate", then enter the mouse over the empty area under the fill line and thus create a key.

The key starts with ssh-rsa and to add it you need to upload it to the server as previously shown in the linux clause. You also need to save it by clicking "Save private key" after that, when downloading via Putty, you will need to select an ssh key before logging in to the server.

Next, click "Browse” and select the ssh key you created earlier, which you saved on your system and added to the server.
After you have selected the required key and clicked "Open", the server will open.

Conclusion

SSH key is a very useful protocol that increases the security of your server and allows you to work remotely and not be afraid of data leakage. In order for you to be able to give access to a remote server and help your employees with completing tasks, it is best to use this particular key-value. Of course, there are some difficulties in order to create your own key for each employee and, in principle, you can get confused with creating the key itself at the initial stage, but your efforts are worth it.

However, if suddenly you are too lazy to do everything yourself, you can use our services. Mivocloud provides you with a lot of opportunities and advantages, for example, you can create an SSH key and add it to the server you are creating. In our service, everything is simple in the settings and there are no problems with adding or removing keys and other things, and if you have questions, you can always watch the video on our channel