19.04.2020»»воскресенье

Generating An Ssh Key In Ubuntu 18.04

19.04.2020

SSH (Secure Shell) is a encrypted protocol which allows client system to communicate securely with a server. You can connect to your system remotely, perform administrative tasks and access files. Communicate with server using SSH keys is more secure and convenient way than password authentication. In this tutorial, we have described how to create SSH keys on Ubuntu 18.04 system and how to copy it to server using different ways.

Mar 11, 2019 Web on Speed Articles Creating SSH keys for your Ubuntu 18.04 Server that enhances security without using plaintext passwords.

Sep 25, 2019  How to access remotely to your host server with ubuntu 18.04 from Mac. In your client computer, enter this command to create ssh public key. Dec 18, 2019 How to Set Up SSH Keys on Ubuntu 18.04 Creating SSH keys on Ubuntu. Before generating a new SSH key pair first. Copy the Public Key to Ubuntu Server. Now that you generated your SSH key pair. Login to your server using SSH keys. After completing the steps above you should be able log in. Sep 25, 2018 In this tutorial we will walk through how to generate SSH keys on Ubuntu 18.04 machines. We will also show you how to setup a SSH key-based authentication and connect to your remote Linux servers without entering a password. Creating SSH keys on Ubuntu. Jul 25, 2019 In this guide, you will learn how to set up SSH keys for Ubuntu 18.04 installation. SSH keys deliver an easy and secure way of logging into your server also is recommended for all users. STEP 1 – Create the RSA Key Pair.

Prerequisites

Before you begin, you should have the non-root user account on your server with sudo privileges.

Creating SSH keys on Ubuntu

At first, we will create a key pair on client system using below command:

By default, ssh-keygen will generate 2048-bit RSA key pair. If you wish to create larger 4096-bit key then you can pass -b 4096 in flag as below:

It should show output like below:

Hit the Enter key to save the key pairs at ./ssh directory or you can specify location as per your choice.

After that, it will prompt to enter a secure passphrase as below. Passphrase will add an additional security layer to your keys. It is optional, if you don’t want to set then you can skip it by just hitting Enter key.

Next, you will see output as following: Pukky key generator does not have ssh-2 won.

Now you have public and private keys which you can use to authenticate with your Ubuntu server.

You also can verify that your files are generated or not by typing:

It will show output like this:

Copy the Public Key to Ubuntu Server

Now, next step is to place public key to your Ubuntu 18.04 server. Simple and fast way to copy public is to use ssh-copy-id utility. Run the below command:

It will be prompted to enter password for your username:

Once the user is authenticate successfully, the public key will be appended to ~/.ssh/authorized_keys file on remote user and connection will be disconnected.

Now you can try login to your machine with command ssh username@server_ip_address and check that only the key(s) added which you want to add.

If your local system don’t have ssh-copy-id utility installed then you can use following command to copy the public key:

Ensure that you have password-based SSH access to your server then only you can use above method.

Login to the Server using SSH Keys

Now, you should be able to login to the remote machine without the remote user’s password.

You can try to connect using SSH command:

If you are first time to login then it may prompt you as following. Type yes and hit Enter key to continue:

Now, if you haven’t set passphrase for your keys then you will be logged in immediately without asking passphrase. Otherwise it will be asked to enter passphrase. After successful authentication, a new shell session will open your user account on the Ubuntu 18.04 server.

Disable SSH Password Authentication

You can add one more security layer by disabling the password authentication for SSH. Before starting process, make sure that you are able to authenticate to your server without entering password and must have sudo enabled user account.

Let’s login to your server using ssh:

Now edit the SSH configuration file located at /etc/ssh/sshd_config:

Find PasswordAuthentication directive and if line commented out then uncomment the line and set the value to “no” as given below:

Save and close the file. You must need to restart the SSH service using below command:

Now, password-based authentication is disabled on your Ubuntu server.

Conclusion

You learned how to create a new SSH keys pair and set up an SSH key-based authentication on Ubuntu 18.04 machine. You can set up same key to multiple remote hosts. At the end, you also learned how to disable SSH password authentication.

By default, SSH listens on port 22. You can reduce the risk of automated attacks by changing the default SSH port.

If you have any question or suggestion, please leave comment below.

SSH stands for “Secure Shell” and is an encrypted protocol used to log in and manage a remote server. SSH also supports various authentication mechanisms. SSH uses password-based authentication and public key-based authentication for a secure connection between a client and a server. SSH key-based authentication is more secure than password-based authentication because keys are very hard to guess or crack using currently available computing power.

In this tutorial, we will show you how to set up SSH key-based authentication on an Ubuntu 18.04 server.

Prerequisites

  • Two fresh Ubuntu 18.04 VPS on the Atlantic.Net Cloud Platform.
  • Root passwords configured on both servers.

Step 1 – Create an Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 18.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged into your Ubuntu 18.04 server, run the following command to update your base system with the latest available packages.

Step 2 – Generate the SSH Key on the Client Machine

First, log in to your client machine and generate a new SSH key pair by running the following command:

You will need to press Enter to accept the default file location and provide a passphrase to add an extra layer of security, as shown below:

The above command will generate a 2048-bit RSA key pair with a secure passphrase to prevent unauthorized users from logging in.

You can see the generated public and private keys with the following command:

You should see the following output:

At this point, you have public and private keys that you can use to authenticate with your Ubuntu server.

Step 3 – Copy the Public Key to the Ubuntu Server

Next, you will need to copy the public key from the client machine to your Ubuntu 18.04 server. You can copy the public key with ssh-copy-id utility as shown below:

You should see the following output:

Type “yes” and press ENTER to continue. You should see the following output:

Next, you will be prompted to enter the remote username and password. After the successful authentication, the content of the public key ~/.ssh/id_rsa.pub will be appended to the remote user ~/.ssh/authorized_keys file as shown below:

Step 4 – Disable SSH Password Authentication

Next, log in to your Ubuntu 18.04 server machine and disable SSH password-based authentication to add an extra layer of security to your server.

You can disable password-based authentication by editing the file /etc/ssh/sshd_config:

Find the following lines and change the value to “no”:

Save and close the file, then restart SSH service to apply the configuration:

Step 5 – Log in to the Server using SSH Keys

At this point, SSH key-based authentication is configured. Now it’s time to log in to the Ubuntu 18.04 server machine with the public key.

You can login to your Ubuntu 18.04 server by simply running the following command:

If you are logging in for the first time, you will be prompted as shown below:

Type Yes and hit Enter key to continue. Next, you will be prompted to enter the passphrase for your private key as shown below:

Provide your private key passphrase and hit Enter to log in to your server.

Conclusion

Ubuntu 18.04 Ssh Connection Refused

In the above tutorial, we learned how to set up an SSH key-based authentication with a passphrase on Ubuntu 18.04. The connection between your client machine and Ubuntu 18.04 server machine is now highly secure. You can also use the same key for another remote server. If you’re ready to get started with SSH key-based authentication, try VPS hosting with Atlantic.Net today.