{"data":{"external_id":1764,"slug":"create-and-use-ssh-key","title":"Create and Use SSH Key","content":"Create and Use an SSH Key\nUsing an SSH key has many benefits. But how do you do it? We&#8217;ll gladly explain it to you in this post. We&#8217;ll show you how to create a new SSH key on Windows and then use it for a secure connection to your vServer.\nFirst, you need to download PuTTY in order to connect to your SSH server. You also need the puttygen.exe.\nCreate Private\/Public Key\nLaunch the downloaded puttygen.exe.\nTo generate an SSH key, click on &#8222;Generate&#8220;. Then, move the mouse cursor randomly across the empty area. This will generate a random code for your key.\nPutty Key Generator\nIn the &#8222;Key comment&#8220; field, enter your name or a comment for the key. In the &#8222;Key Passphrase&#8220; and &#8222;Confirm passphrase&#8220; fields, enter a secure password for your key. You can leave it blank, but it is not recommended.\nAll you have to do now is save the Public Key (e.g. public-key.txt) and the Private Key (e.g. private.ppk) on your hard drive.\nNow connect to your vServer. Log in as Root.\nCreate the folder &#8222;\/root\/.ssh&#8220;. This folder will store the public keys. In the newly created folder, create a file called authorized_keys.\nInstall Key on the Server\nNow open your Public Key on your computer using an editor (such as Notepad or Windows Editor) and copy its contents. The public key can be seen by others because it will be stored on the server. It is the counterpart to your private key, which you will use to log in to the server later.\nOpen the file with, for example, nano (nano \/root\/.ssh\/authorized_keys), and insert the public key there.\nImportant: The key must start with &#8222;ssh-rsa&#8220; and must not contain new lines. Everything must be in one line. Please remove any unnecessary &#8222;new lines&#8220;.\nExample key:\nssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEArmkSugnahfqXyCeuxbHjOjTqx7VFt1l4KLY+\/zTe4IgIJY+xs8TkWDi+CFaMAJlMQdknbV7v\/Suio7\/7fS9cvsumu0XpRsRn\/hZmBQPhIZlkjJeG9lGUYS1Jr09eyT2fRUEUyb9Qqc8Wdz5eWWBk2y52\/xWScgR9nbMzABmv5ucH9z1d2od8rqm93B5haLmVljxRJG3OsYPFB93M4vByj\/bptcSroZhJoyKcmIvKsV+6a8HDVw47KSub4wRdACcpHjYdKIDubtEQM8z8y0pdSDxcfi\/SVxD2eTewhT6j1uAT1wrTes6EO0V69EwWAa5L+n\/oiMnXwSgu9Xd2AXZgRw== Dennis Ziolkowski\nSave and finish. Now you just need to establish a connection using the Private Key.\nTo do this, open PuTTY. Click on the entry under &#8222;Configuration &gt; Connection &gt; SSH &gt; Auth&#8220; and search for your private key in the field &#8222;Private key file for authentication&#8220;.\nChoose SSH Key\nGo back to the &#8222;Session&#8220; entry and connect to your server as usual. It&#8217;s best to save the data under &#8222;Saved Sessions&#8220; so you don&#8217;t have to repeat the step every time.\nNow the connection to your server opens. You should now be prompted to enter the passphrase for your private key. Enter the password, confirm with Enter, and voil\u00c3\u00a0: you have successfully logged in to your server using your key.\nDisable Password Authentication\nTo ensure that you can now only log in to your server using the keys from authorized_keys, you need to disable password authentication in the SSH server configuration. To do this, open the configuration file at \/etc\/ssh\/sshd_config.\nFind the line &#8222;PasswordAuthentication&#8220; and set the value to &#8222;no&#8220;. Save the configuration and restart the SSH server with &#8222;service sshd restart&#8220;. Your server is now more secure.\nTake Further Security Measures\nYou are not 100% secure yet. For example, you should definitely change the default port of the SSH server. We also recommend installing fail2ban.\nIf you have any questions, please don&#8217;t hesitate to contact us.","schema":null,"facts":[],"links":[{"type":"external","url":"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html","data":{"title":"Download PuTTY: latest release (0.83)","meta_description":"","meta":{"":"text\/html; charset=UTF-8"}}},{"type":"external","url":"https:\/\/the.earth.li\/~sgtatham\/putty\/latest\/w64\/puttygen.exe","data":{"title":"","meta_description":"","meta":[]}}]}}