Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Configuring Key-Based Authentication

A strong password is typically composed of upper-case and lower-case letters, numbers, and special characters. You can even create a 20-character password and, in all likelihood, nobody will ever guess it. But do you really want to type in a 20-character password every time you need to access the server? Maybe you might, but most people really do not want to. Therefore, in this lab, we will configure SSH key-based authentication, which is far more secure and you do not have to type in any passwords when you log in to the server. Furthermore, when key-based authentication is configured, most people forget to disable password-based authentication altogether. We will not forget to do this. Finally, we will also disable root-based login as an extra security precaution.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 45m
Published
Clock icon Oct 18, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Generate a Key Pair on the Client for SSH

    Note: For this lab, the use of a standalone terminal app with ssh support is best as the Instant Terminal does not permit port 61613. The instance does take a minute or so to be ready to be connected to via ssh. Please use port 61613 when connecting to this lab.

    ssh-keygen
    
  2. Challenge

    Copy the Newly Created Key Over to the Server

    1. Open your newly created key (replace <PATH_TO_PUBLIC_KEY> with your path):

      vim <PATH_TO_PUBLIC_KEY>
      
    2. Select all and copy.

    3. Open /home/cloud_user/.ssh/authorized_keys:

      vim /home/cloud_user/.ssh/authorized_keys
      
    4. Paste in the public key.

    5. Save and quit:

      ESC
      :wq
      ENTER
      
  3. Challenge

    Configure SSH to Not Allow Root Login or Password-Based Authentication and to Allow Key-Based Authentication

    1. Open the file:

      sudo vim /etc/ssh/sshd_config
      
    2. Make the following changes:

      PermitRootLogin no
      PasswordAuthentication no
      ChallengeResponseAuthentication no
      PubkeyAuthentication yes
      
    3. Save and quit:

      ESC
      :wq
      ENTER
      
    4. Restart the sshd service:

      sudo systemctl restart sshd
      
  4. Challenge

    Test the New Configuration by Logging Out and Back in with the Newly Created Key

    1. Log out:

      exit
      
    2. Log in with the newly created key (replace <PATH_TO_PRIVATE_KEY> with your path):

      ssh cloud_user@SERVER_IP -p 61613 -i <PATH_TO_PRIVATE_KEY>
      

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans