ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Ubuntu 18.04 Ssh Key Generate
    카테고리 없음 2020. 8. 28. 22:03



    Jul 09, 2018  How to Add an SSH Public Key to GitHub from Ubuntu 18.04 LTS July 9, 2018 “How to Add an SSH Public Key to GitHub from an Ubuntu 18.04 LTS System” covers the entire process of creating an SSH key pair on an Ubuntu 18.04 LTS system and adding the public key to GitHub. The first thing that we need to do is create an SSH key pair to use.

    There are many reasons you might want to create a key pair on Linux, more specifically on Ubuntu.

    For more information about key pairs, see this.

    If your server is an Amazon EC2 Server Instance, you might want to look at more specific information here

    Key pairs are just one way to log into a system. (Perhaps the one you currently use is regular username and password ssh login). Key pairs are generally more secure than password logging in.

    One thing you have to keep in mind is that using key pairs is a two-way method: you'll need to create a private key and a public-key.

    Personally, I use them so I can use git remotely. Another very common use of public/private key pairs is when you want to, for example, scp a file from your local server into a remote server without needing to type the ssh password lots of times. Another good reason to use this is to disable anyone from logging into your server, which reduces the chance someone will break into your server.(I'm not an expert on security so do you own research before securing your web server, as it's a very important step.)

    Ok so let's start: Ubuntu has a very handy way to accomplish this:

    Create yourself a .ssh directory if you don't already have one.

    Then type this command to create the key per se:

    (you'll be prompted for a passphrase. It adds another layer of security still. You can choose one or leave it blank.)

    cd to your home folder to check the key has been created:

    You should see two files: id_rsa and id_rsa.pub.

    Now you'll need to transfer the public key (the .pub file) to your remote server. Again, Ubuntu has a simple command to do this:

    If the last step was successful, you should be able to log into your server with no password (only from this machine, of course!. Ubuntu will use the private key wev'e just created to authenticate.)

    et voilà

    troubleshooting: if a command isn't working, try issuing that command again with sudo.

    see also: official ubuntu docs

    Ubuntu 18.04 ssh key generate linux

    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

    18.04

    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:

    Ubuntu Ssh Key Generate

    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”:

    Generate

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

    Step 5 – Log in to the Server using SSH Keys

    Ssh Key Setup

    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

    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.





Designed by Tistory.