SSH public key authentication explained | NordVPN (2024)

Contents

  • What is SSH public key authentication?
  • How does SSH public key authentication work?
  • What are the benefits of using an SSH public key?
  • How to generate an SSH public key
    • Generate an SSH public key on Mac and Linux
    • Generate an ssh public key on Windows

What is SSH public key authentication?

Secure Shell (SSH) public key authentication is a method that allows a user device to pair with remote servers and systems using cryptographic key pairs. Once authenticated, the user device establishes an encrypted connection with the server for safe data transfer. SSH public key authentication provides resilient security against malicious attacks and account intrusions thanks to its two inherent parts:

  • SSH, which is a cryptographic network protocol created for secure communication over an unsecured network. SSH provides strong encryption for sent data and is compatible with various authentication forms, including password-based and public key authentication.
  • Public key authentication, which uses an asymmetric cryptographic algorithm to generate two cryptographic keys — private and public — to authenticate and connect devices. Cryptographic key pairs are a part of a public key infrastructure (PKI) that is considered superior to password authentication because of its resistance to brute force attacks and other phishing attempts.

When authentication with SSH keys is established, the user obtains their digital identity by generated private key. In contrast, its pair, a public key, is distributed among SSH-connected servers and systems the user wants to access. Once the SSH connection is established, the user doesn’t need to use a password to reach remote resources in the future — the authentication system can compare the cryptographic keys without the user’s involvement and connect them to the needed assets. However, the user can create a passphrase to unlock their private key for additional security. Afterward, they would need to provide it any time they want to authenticate their identity with SSH. In addition, SSH encrypts all the data sent between the user and the remote server.

SSH public key authentication allows for easier user identity and access management and can make automation processes smoother.

How does SSH public key authentication work?

SSH public key authentication works by generating a pair of cryptographic keys, one private and one public, that are exclusive to each other. They are used to identify users and grant them access to a particular SSH server or system. Both the user and SSH server use the public key to encrypt messages during the connection sessions. The user can choose to distribute their public key to as many servers, systems, and machines as they wish. Meanwhile, the private key is used to sign authentication messages sent by the SSH server and remains only with the user, safely stored on the device they use. As mentioned previously, the private key may also be protected with a passphrase for higher security.

Let’s take a more precise look at how SSH public key authentication works:

  1. The user tries to access the resources stored in the SSH server and initiates a connection with it.
  2. The server recognizes the user’s public key and creates a challenge — an algorithm of random numeric combinations of varying lengths.
  3. The SSH server prompts the user, or rather the device the user employs for the connection, to sign the challenge using their private key. The private key is typically generated using the RSA, DSA, ECDSA, or EdDSA algorithms. The most widely used among them are RSA and ECDSA. If the user has set a passcode to their private key, now is the time for them to provide it.
  4. The user’s device signs the challenge with their private key and returns it to the server.
  5. The server checks the private key’s signature against its corresponding public key. If the private key is verified, the user is authenticated and can connect to the SSH server.

Once the remote server authenticates the user, their device establishes an encrypted tunnel with that server. That means that all the data sent between the two is encrypted before it gets into the tunnel and decrypted after exiting the tunnel on the other end.

SSH public key authentication provides a robust authentication process with an encrypted connection between the devices, allowing for better network security.

What are the benefits of using an SSH public key?

SSH public key authentication benefits include boosting the security of the connection between multiple systems and devices and providing a safer exchange of data between two remote ends over unsave networks. Below are some of the major benefits SSH public key infrastructure offers in more detail:

  • Multiple logins. Multiple users can connect to the same SHH server or system using their public keys without sharing their login credentials with other users. In addition, SSH public key authentication allows the revocation of access to single-user accounts without compromising the access of the rest of the users.
  • Enhanced security. SSH public key infrastructure provides strong authentication because its asymmetric encryption is complex and challenging for attackers to break. This type of authentication also doesn’t rely on sending passwords over the network, which lowers the risk of them being intercepted.
  • Automation and scalability. SSH servers can store numerous public keys within their system, allowing companies to expand or reduce user access according to their needs. SSH public key authentication also accommodates single sign-on (SSO): The user can use the same public key to gain access across multiple servers.

How to generate an SSH public key

Users can generate SSH keys by themselves using the open-source suite OpenSSH. However, for the authentication to work properly, the remote system you will share your public key with must have the same version of SSH installed. You also need to have access to the remote system to transfer the generated public key. Below are instructions for creating your own SSH key pair using OpenSSH and an RSA algorithm for generating the private key.

Generate an SSH public key on Mac and Linux

Follow these instructions to generate SSH public and private keys on Mac and Linux operating systems:

  1. Install OpenSSH onto your computer and open the SSH suite. Enter ssh-keygen -t rsa in the command line to generate RSA keys.
  2. You’ll be asked to create a file name and passphrase for your private key to safeguard it.
    • Filename. You can accept the suggested default filename, which will look something like ~/.ssh/id_rsa, and your key pair file’s default location by pressing “Enter” or “Return.” You can also create your own filename. However, remote systems are typically configured to recognize and accept private keys with their default filenames. This means that introducing another filename may require additional steps. The following instructions will cover the process of establishing SSH key authentication using the default filename.
    • Passphrase. You can either create one or proceed without the passphrase. If you decide to use the passphrase, you’ll need to provide it every time you connect to the system with a corresponding public key. If you tap “Enter” and “Return” without entering the passphrase, your private key won’t have one. If you decide to create a passphrase, make sure it’s at least five characters long and then tap “Enter” or “Return.”
  3. Once you decide on the filename for your key pair, the SSH suite will generate a private key using the filename and store it on your computer in the .ssh directory of your home directory. The system will also generate a corresponding public key using the same filename but with the .pub extension added, for instance, ~/.ssh/id_rsa.pub, and will store it in the same location on your computer as the private key.
  4. Use the SSH file transfer protocol (SFTP) or SCP command line of the SSH suite to copy the public key file and place it in your account on the remote system, for instance: scp ~/.ssh/id_rsa.pub name@surname.com. Keep in mind that during this step, you’ll be asked to enter the credentials for your account on the remote system. Afterward, your public key will be saved in this new format in both your home directory and the remote system.
  5. Log in to the remote system and check if it contains the ~/.ssh/authorized_keys file. If it doesn’t, use the command line to enter mkdir -p ~/.ssh and touch ~/.ssh/authorized_keys.
  6. Now you should add the contents of your public key file (using the previous example — ~/id_rsa.pub) to the remote system. You should add them to a new line in your ~/.ssh/authorized_keys file, entering cat ~/id_rsa.pub >> ~/.ssh/authorized_keys in the command line.
  7. After that, you can either delete your public key (~/id_rsa.pub) from your account on the remote system or keep it and move it to the remote system’s .ssh directory.
  8. Using the ssh command, you can access your account on the remote system (name@host2.surname.com) from your computer (host1). If you’ve safeguarded your private key with a passphrase, you’ll be prompted to provide it.

Generate an ssh public key on Windows

Follow these instructions to generate SSH public and private keys on Windows10 or newer Windows operating systems:

  1. Open the Windows command prompt window by typing cmd in the search box.
  2. Type ssh-keygen in the prompt. The command will start to generate the SSH keys.
  3. Tap “Enter” to save the keys in the default location or pick another location for the files.
  4. The prompt will open, asking you to create and confirm the passphrase to secure the private key. Press “Enter” after creating the passcode. You can also go without creating a passphrase by leaving the field for the passphrase empty and pressing “Enter.”
  5. Now, you’ll need to configure the remote system you want to connect to. First, check if it has a ~/.ssh folder by entering ls -l ~/.ssh/ in the command prompt. If you discover that the folder doesn’t exist, create it by entering mkdir ~/.ssh and changing its permissions to chmod 700 ~/.ssh.
  6. Create a file and call it authorized_keys in the ~/.ssh directory by entering touch authorized_keys in the command prompt. Afterward, change the permissions to chmod 600 ~/.ssh/authorized_keys.
  7. Open the authorized_keys file using a text editor and copy the public key contents into the authorized_keys file. Save and close the file.
  8. Log in to the remote server from your computer using the command ssh @. A prompt will appear asking you to enter the passphrase for your private key if you created one. Afterward, the command will use SSH to let you access the remote server.

Conclusion

SSH public key authentication helps users to safely access remote servers, devices, and systems with as little input from the user as possible. Paired with SSH encryption, public key infrastructure allows for a secure connection and data transfer between devices, which then become more resilient to malicious attacks and unauthorized interceptions.

SSH public key authentication explained | NordVPN (2024)

FAQs

SSH public key authentication explained | NordVPN? ›

Secure Shell (SSH) public key authentication is a method that allows a user device to pair with remote servers and systems using cryptographic key pairs. Once authenticated, the user device establishes an encrypted connection with the server for safe data transfer.

How to public key authentication in SSH? ›

The SSH public key authentication has four steps:
  1. Generate a private and public key, known as the key pair. ...
  2. Add the corresponding public key to the server.
  3. The server stores and marks the public key as approved.
  4. The server allows access to anyone who proves the ownership of the corresponding private key.
Aug 10, 2021

How does the SSH public key work? ›

The SSH server recognizes that a connection is being requested and sends an encrypted challenge request using the shared public key information. The SSH client then decrypts the challenge message and responds back to the server. The user or process must respond correctly to the challenge to be granted access.

What are the disadvantages of SSH public key authentication? ›

Despite the benefits, using keys for SSH authentication also has some drawbacks. First, keys are more difficult to set up and maintain than passwords. You need to generate, distribute, and store your keys securely, and update them regularly.

What are the authentication permissions for SSH public key? ›

ssh directory permissions should be 700 (drwx------). The public key (. pub file) should be 644 (-rw-r--r--). The private key (id_rsa) on the client host, and the authorized_keys file on the server, should be 600 (-rw-------).

How to validate SSH public key? ›

Procedure
  1. Log in the server as 'root' using SSH, or use the WHM: Terminal feature.
  2. Change into the /root/. ssh/ directory on the server. ...
  3. Use the command 'ls -al' to list all files in the directory, and locate your private/public keypair you wish to check. ...
  4. Use the following command, to test both files. ...
  5. That's it.
Oct 31, 2021

What is the difference between authentication and signing SSH keys? ›

The difference between signing keys and authentication keys is that signing keys can be used to sign Git commits and authentication keys can be used to access repositories. If you add a key as only one type, then it can be used only for that purpose, but the same key may be added for both.

What is the process of public key authentication? ›

The user generates a key pair on his own computer, and copies the public key to the server. Then, when the server asks him to prove who he is, a signature is generated using his private key. The server can verify that signature (since it has his public key) and allow him to log in.

How to read a public SSH key? ›

The first method is to use the cat command:
  1. Using the run command.
  2. Execute the following command. cat ~/.ssh/id_rsa.pub. The command will display your SSH key on your Linux machine without requiring your key authentication password.
Sep 12, 2023

What is the public key authentication flow? ›

Secure Shell (SSH) public key authentication is a method that allows a user device to pair with remote servers and systems using cryptographic key pairs. Once authenticated, the user device establishes an encrypted connection with the server for safe data transfer.

Why use ssh key instead of password? ›

From a security standpoint, using SSH-keys to authenticate a user's identity leads to greater protection of your data. Username/password authentication can often lead to security compromises, in particular, brute force attacks by hackers.

Is it safe to email SSH public key? ›

Generally it may be a good idea to add the fingerprint to your email signature. Not sure if it is necessary though to attach your own public key to all your emails. However there is no security or privacy concern in doing so. Although some mail clients or servers may increase their spam score for the attachment.

Is it safe to use SSH key without password? ›

SSH Passwordless Login FAQ

If you simply press Enter without typing a passphrase, the key will be created without one. While this allows for passwordless authentication, it is important to note that such a key is less secure because it can be used by anyone who obtains the private key.

Do I need to restart SSH after adding a key? ›

Issue: When you generate a new SSH key, you need to restart the SSH server for the new key to take effect. Update: SSH keys are now available for new connections immediately without a server restart as of Oracle ILOM 3.0.

How to setup public key authentication for SSH? ›

On your computer, in the PuTTYgen utility, copy the contents of the public key (displayed in the area under "Key") onto your Clipboard. Then, on the remote system, use your favorite text editor to paste it onto a new line in your ~/.ssh/authorized_keys file, and then save and close the file.

What are the three authentication methods supported by SSH? ›

Secure Shell User Authentication Overview

The SSH server supports three types of user authentication methods and sends these authentication methods to the SSH client in the following predefined order: Public-key authentication method. Keyboard-interactive authentication method. Password authentication method.

How do I access my SSH public key? ›

Command Prompt (for Windows 10 only)
  1. Open Command Prompt or Windows PowerShell.
  2. Issue the command: ssh-keygen.
  3. To view public key, navigate to C:\Users\<username>/.ssh/id_rsa.pub (see image below) or execute this command in the command prompt: more C:\Users\<username>/.ssh/id_rsa.pub.
Sep 13, 2022

Can public key be used for authentication? ›

Public key authentication provides cryptographic strength that even extremely long passwords can not offer. With SSH, public key authentication improves security considerably as it frees the users from remembering complicated passwords (or worse yet, writing them down).

How to generate SSH key for authentication? ›

Launch Terminal and enter the following command:
  1. ssh-keygen -t rsa -b 4096. Click to copy. ...
  2. Enter file in which to save the key(/Users/username/.ssh/id_rsa): Click to copy. ...
  3. Enter passphrase (empty for no passphrase): ...
  4. Enter same passphrase again: ...
  5. Your identification has been saved in /Users/yourname/.ssh/id_rsa.

How do I enable password authentication with SSH? ›

Configure password-based SSH authentication
  1. Log in to the server console as the bitnami user.
  2. Edit the /etc/ssh/sshd_config and modify or add the following line: PasswordAuthentication yes.
  3. Restart the SSH server for the new configuration to take effect: sudo /etc/init.d/ssh force-reload sudo /etc/init.d/ssh restart.
Oct 10, 2022

Top Articles
The 7 Best Inflation Hedge Assets and ETFs for 2024
SPY - S&P 500 SPDR ETF Trader's Cheat Sheet - Barchart.com
Creepshotorg
It’s Time to Answer Your Questions About Super Bowl LVII (Published 2023)
Nybe Business Id
4-Hour Private ATV Riding Experience in Adirondacks 2024 on Cool Destinations
Le Blanc Los Cabos - Los Cabos – Le Blanc Spa Resort Adults-Only All Inclusive
Room Background For Zepeto
Professor Qwertyson
Es.cvs.com/Otchs/Devoted
Osrs Blessed Axe
Slag bij Plataeae tussen de Grieken en de Perzen
Things To Do In Atlanta Tomorrow Night
Think Up Elar Level 5 Answer Key Pdf
Craigslist Deming
Flower Mound Clavicle Trauma
Aberration Surface Entrances
Define Percosivism
Best Forensic Pathology Careers + Salary Outlook | HealthGrad
Webcentral Cuny
24 Hour Drive Thru Car Wash Near Me
St. Petersburg, FL - Bombay. Meet Malia a Pet for Adoption - AdoptaPet.com
Nevermore: What Doesn't Kill
Aldi Bruce B Downs
Helpers Needed At Once Bug Fables
Student Portal Stvt
Calvin Coolidge: Life in Brief | Miller Center
What Is The Lineup For Nascar Race Today
Why Are The French So Google Feud Answers
Autotrader Bmw X5
Workboy Kennel
Rust Belt Revival Auctions
#scandalous stars | astrognossienne
How to Draw a Sailboat: 7 Steps (with Pictures) - wikiHow
Mvnt Merchant Services
Has any non-Muslim here who read the Quran and unironically ENJOYED it?
Uvalde Topic
Citibank Branch Locations In Orlando Florida
Cpmc Mission Bernal Campus & Orthopedic Institute Photos
The Conners Season 5 Wiki
The Attleboro Sun Chronicle Obituaries
The power of the NFL, its data, and the shift to CTV
Yale College Confidential 2027
The Horn Of Plenty Figgerits
Embry Riddle Prescott Academic Calendar
Professors Helpers Abbreviation
15 Best Places to Visit in the Northeast During Summer
How to Connect Jabra Earbuds to an iPhone | Decortweaks
Gander Mountain Mastercard Login
Enter The Gungeon Gunther
Www.homedepot .Com
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 6377

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.