sammlinux sammlinux
  • Ubuntu
    UbuntuShow More
    How To Install and Use Docker CE on Ubuntu 22.04
    26 Min Read
    How To Install and Secure phpMyAdmin on Ubuntu 22.04
    5 Min Read
    How To Secure SSH with Fail2Ban on Ubuntu 22.04
    8 Min Read
    How To Install Uptime Kuma on Ubuntu 22.04
    17 Min Read
    How To Install Ubuntu Server 22.04 LTS with Screenshots
    14 Min Read
  • Rocky Linux
    Rocky LinuxShow More
    How To Install phpMyAdmin on Rocky Linux 9
    15 Min Read
    How To Secure SSH with Fail2Ban on Rocky Linux 9
    12 Min Read
    How To Install Rocky Linux 9.2 Server with Screenshots
    12 Min Read
    How To Set Up a Firewall Using FirewallD on Rocky Linux 9
    8 Min Read
    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
    10 Min Read
  • Debian
    DebianShow More
    How To Secure SSH with Fail2Ban on Debian 11
    8 Min Read
    How To Install Debian 11 (Bullseye) Server with Pictures
    12 Min Read
    How To Install and Setup Node.js on Debian 11
    6 Min Read
    How To Install PHP 8.2 on Debian 11
    12 Min Read
    How To Install Nginx on Debian 11: A Comprehensive Guide
    9 Min Read
  • Linux
    LinuxShow More
    Best Practices Linux Server Security for System Administrator
    8 Min Read
    A Simple Guide: How To Manage Groups on Linux
    5 Min Read
    How To Manage Log Files Using Logrotate In Linux
    7 Min Read
    The Easy Ways to Check File Size in Linux
    7 Min Read
    How To Backup Files From Remote Linux VPS Using Rsync Script
    12 Min Read
  • CentOS
    CentOSShow More
    How To Secure SSH with Fail2Ban on CentOS 7
    9 Min Read
    How To Install PHP 8.2 on CentOS 7 / RHEL 7
    18 Min Read
    How To Install Apache Web Server on CentOS 7
    11 Min Read
    How To Set Up a Firewall Using FirewallD on CentOS 7
    5 Min Read
    Initial Setup CentOS 7 Server: Secure and Efficient
    9 Min Read
  • DevOps
    DevOpsShow More
    How To Create AWS CloudFront: A Step-by-Step Guide
    10 Min Read
Reading: How To Configure SSH Key-based Authentication In Linux
Share
Font ResizerAa
Linux for BeginnersLinux for Beginners
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Search
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.

How To Configure SSH Key-based Authentication In Linux

Samuel Siahaan
By Samuel Siahaan
Last updated: November 4, 2023
SHARE

In the ever-evolving world of cybersecurity, safeguarding your Linux server is of paramount importance. One crucial aspect of securing your server is configuring SSH key-based authentication. In this step-by-step guide, we will walk you through the process of setting up/ Configure Secure SSH key-based authentication in Linux, ensuring a higher level of security while making the login process more straightforward.

Contents
Table of ContentsWhat Is SSH Key-Based Authentication?Why Use SSH Key-Based Authentication?Configure SSH Key-based Authentication In LinuxStep 1: Generate an SSH Key PairStep 2: Copy the Public Key to the ServerStep 3: Disable Password AuthenticationStep 4: Test Your SSH Key-Based AuthenticationAdditional Security TipsConclusion

Table of Contents

  • What Is SSH Key-Based Authentication?
  • Why Use SSH Key-Based Authentication?
  • Configure SSH Key-based Authentication In Linux
    • Step 1: Generate an SSH Key Pair
    • Step 2: Copy the Public Key to the Server
    • Step 3: Disable Password Authentication
    • Step 4: Test Your SSH Key-Based Authentication
  • Additional Security Tips
  • Conclusion

What Is SSH Key-Based Authentication?

SSH, which stands for Secure Shell, is a widely used protocol for securely connecting to remote servers and managing them. SSH key-based authentication is a method of proving your identity to the server without using a password. Instead, it relies on cryptographic keys, making it a much more secure and convenient way to access your server.

Why Use SSH Key-Based Authentication?

Using SSH key-based authentication offers several benefits:

  • Enhanced Security: Passwords can be guessed or cracked, but SSH keys provide a higher level of security as they are nearly impossible to brute force.
  • No More Passwords: You can log in without entering your password each time, saving you time and effort.
  • Automation: SSH keys are a preferred method for automated processes and scripts, allowing secure, passwordless interactions with the server.

Now, let’s get started with the configuration process.

- Advertisement -

Configure SSH Key-based Authentication In Linux

In this guide, we will walk through the process of configuring SSH key-based authentication in Linux using Ubuntu Linux and Rockylinux systems as an example.

  • The local system, running Ubuntu 22.04 Desktop, has the IP address 172.32.1.224/24
  • While the remote system, acting as an SSH server, runs Rockylinux 9.2 Server with the IP address 172.32.1.223/24.

Step 1: Generate an SSH Key Pair

The first step is to generate an SSH key pair. To do this, open your terminal and enter the following command:

$ ssh-keygen -t rsa -b 4096 -C "samm@ubuntu"

This command will generate a pair of keys: a private key (usually stored on your local machine) and a public key (to be placed on the server).

Generate SSH
Generate SSH

To update your SSH key with a passphrase, follow these steps if you already have an SSH key without a passphrase in the private file ~/.ssh/id_rsa Open your terminal and use the following command:

$ ssh-keygen -p -f ~/.ssh/id_rsa

Step 2: Copy the Public Key to the Server

Now that you have your SSH key pair, you need to copy the public key to your server. Use the following command to do so, replacing [username] and [server_ip] with your server’s username and IP address:

- Advertisement -
ssh-copy-id [username]@[server_ip]

You’ll be prompted to enter your server password. Once you’ve done this, your public key will be added to the ~/.ssh/authorized_keys file on the server.

Copy SSH Public Key to SSH Server
Copy SSH Public Key to SSH Server

If you have previously copied the key but wish to update it with a new passphrase, utilize the -f option to overwrite the existing key, as demonstrated below:

$ ssh-copy-id -f [email protected]

Step 3: Disable Password Authentication

To ensure that only SSH key-based authentication is allowed, you should disable password authentication. Open your SSH configuration file using a text editor like nano or vim:

- Advertisement -
sudo nano /etc/ssh/sshd_config

Look for the line that says PasswordAuthentication and change its value to no:

PasswordAuthentication no

Save and exit the file. Then, restart the SSH service to apply the changes:

sudo systemctl restart sshd

Step 4: Test Your SSH Key-Based Authentication

Before you log out of your current SSH session, it’s essential to test the new configuration to ensure it works correctly. Open a new terminal window and try to SSH into your server:

ssh [username]@[server_ip]

If everything is configured correctly, you should be logged in without entering a password.

Login To Server Using SSH
Login To Server Using SSH

Additional Security Tips

While SSH key-based authentication significantly enhances the security of your Linux server, here are some additional tips to consider:

  • Use Strong Passphrases: If you choose to add a passphrase when generating your SSH key pair, make sure it’s strong and unique.
  • Regularly Update Your Keys: Rotate your SSH keys periodically to maintain security.
  • Limit SSH Access: Restrict SSH access to only trusted IP addresses or networks using the sshd_config file.
  • Monitor Your Server: Keep an eye on server logs for any unusual activities.

Conclusion

In conclusion, configuring SSH key-based authentication in Linux is an essential step in securing your server and ensuring seamless, authorized access. By following this step-by-step guide, you can enhance your server’s security posture while simplifying access management.

By understanding the fundamentals of SSH key-based authentication, generating your key pair, and following best practices, you’ll fortify your Linux server against unauthorized access attempts effectively.

Remember, digital security is an ongoing process. Stay vigilant, keep your systems up to date, and always be proactive in adopting the latest security measures to protect your valuable data and assets.

Also Read Our Other Guides :

  • Initial Setup Debian 11 Server: Secure and Efficient
  • Initial Setup CentOS 7 Server: Secure and Efficient
  • Initial Setup Rocky Linux 9 Server: Secure and Efficient
  • How To Set Up a Firewall with UFW on Ubuntu 22.04
  • How To Set Up a Firewall with UFW on Debian 11
  • How To Manage Log Files Using Logrotate In Linux

Finally, now you have learned how to configure ans secure SSH Key-based Authentication In Linux

TAGGED:LinuxSecuritySSH

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article How To Secure SSH with Fail2Ban on Rocky Linux 9
Next Article How To Backup Files From Remote Linux VPS Using Rsync Script
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

How To Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu
Install and Configure Docker Swarm Mode on Centos 7
CentOS
How To Install and Config Thumbor on Debian 10
Debian
How To Install MariaDB 10.6 on Debian 11 Server
Debian
How To Install MongoDB 6.0 on Debian 10 & 11
Debian

You Might Also Like

Linux

6 Methods To Search For Files By Name In Linux

7 Min Read
Linux

Best Practices Linux Server Security for System Administrator

8 Min Read
Linux

The 40 Most-Used Basic Linux Commands You Should Know

15 Min Read
Linux

How To Install and Use Linux Screen with Commands

9 Min Read
CentOS

Initial Setup CentOS 7 Server: Secure and Efficient

9 Min Read
Linux

How To Manage Log Files Using Logrotate In Linux

7 Min Read
Linux

The Easy Ways to Check File Size in Linux

7 Min Read
Rocky Linux

Initial Setup Rocky Linux 9 Server: Secure and Efficient

18 Min Read
Show More

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

sammlinux sammlinux

Providing beginner-friendly Linux tutorials and open-source guides to simplify your digital infrastructure.

www.sammlinux.com © 2026 | All Rights Reserved

Join Us!
Subscribe to our newsletter and never miss our latest news, podcasts etc.

Subscribe to our newsletter to get our newest articles instantly!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?