Detailed Description of How to Configure Authorized Keys for OpenSSH (2024)

Authorized keys specify which users are allowed to log into a server using public key authentication in SSH.

In OpenSSH, authorized keys are configured separately for each user, typically in a file called authorized_keys.

Contents

Location of the Authorized Keys File Generating New Keys Format of the Authorized Keys File cert-authority command="cmd" environment="NAME=value" from="pattern-list" no-agent-forwarding no-port-forwarding no-pty no-user-rc no-x11-forwarding permitopen="host:port" principals="principals" tunnel="n" Key Management for OpenSSH

Location of the Authorized Keys File

With OpenSSH, the authorized keys are by default configured in .ssh/authorized_keys in the user's home directory. Many OpenSSH versions also look for ssh/authorized_keys2. Some organizations use custom OpenSSH builds with different default paths.

The AuthorizedKeysFile configuration option in /etc/ssh/sshd_config specifies where the SSH server looks for authorized keys. The option may contain more than one location, separated by spaces. %% is replaced by literal %, %h by the home directory of the user being authenticated, and %u by the login name of the user. For example, /var/ssh/%u/ak would cause the SSH server to look for authorized keys for the user jane from /var/ssh/jane/ak.

The AuthorizedKeysCommand option can be used to specify a program that is used to fetch authorized keys for a user. The program gets as argument the user name for which to look for keys. A common use of this option is to fetch authorized keys from an LDAP directory.

When selecting a solution for managing SSH keys, it is important to ensure it understands SSH configuration files and can parse the locations where keys are stored, and is able to deal with custom builds used in the organization, if any. Support for the AuthorizedKeysCommand may also be an important consideration, particularly in cloud environments.

Generating New Keys

New key pairs can be generated using the ssh-keygen program and the ssh-copy-id tool can be used for copying keys in an authorized_keys file on a server. It is almost too easy, and that is one of the reasons why the number of SSH keys has become so uncontrolled.

In a locked-down environment, a proper key management tool such as Universal SSH Key Manager would normally be used. Such tools can handle keys in root-owned locations and alert if a root user installs an unauthorized key.

Detailed Description of How to Configure Authorized Keys for OpenSSH (1)Format of the Authorized Keys File

In OpenSSH, a user's authorized keys file lists keys that are authorized for authenticating as that user, one per line. Lines starting with # and empty lines are ignored.

Each line contains a public SSH key. The public key may be preceded by options that control what can be done with the key.

The following options are supported in authorized_keys files.

cert-authority

Indicates that the key should be trusted as a certificate authority to validate proprietary OpenSSH certificates for authenticating as that user. We strongly recommend against using this option, as using OpenSSH certificates for user authentication makes it impossible to audit who has access to the server by inspecting server configuration files, and no trustworthy OpenSSH certificate authority exists.

command="cmd"

Forces a command to be executed when this key is used for authentication. This is also called command restriction or forced command. The effect is to limit the privileges given to the key, and specifying this options is often important for implementing the principle of least privilege. Without this option, the key grants unlimited access as that user, including obtaining shell access.

It is a common error when configuring SFTP file transfers to accidentally omit this option and permit shell access.

environment="NAME=value"

Specifies an environment variable and its value to be added to the environment before executing shell or command.

from="pattern-list"

Specifies a source restriction or from-stanza, restricting the set of IP addresses or host names from which the reverse-mapped DNS names from which the key can be used.

The patterns may use * as wildcard, and may specify IP addresses using * or in CIDR address/masklen notation. Only hosts whose IP address or DNS name matches one of the patterns are allowed to use the key.

More than one pattern may be specified by separating them by commas. An exclamation mark ! can be used in front of a pattern to negate it.

no-agent-forwarding

Prevents forwarding the SSH authentication agent.

no-port-forwarding

Prevents port forwarding for connections using this key. This can be important for, e.g., keys intended to be used only with SFTP file transfers.

Forgetting to disable port forwarding can allow SSH tunneling to be performed using keys only intended for file transfers.

no-pty

Prevents allocation of a pseudo-tty for connections using the key.

no-user-rc

Disables execution of .ssh/rc when using the key.

no-x11-forwarding

Prevents X11 forwarding.

permitopen="host:port"

Limits port forwarding only to the specified port on the specified host. * as port allows all ports. More than one host and port can be specified using commas.

principals="principals"

On a cert-authority line, specifies which users (principal name in proprietary OpenSSH certificates) can log in using their certificate. Use of this option (or cert-authority) is not recommended, as it makes impossible to audit (by inspecting the server) how many different keys grant access as that user, and OpenSSH certificate authorities are not generally very secure.

tunnel="n"

Specifies a tunnel device number to be used if the client requests IP packet tunneling after logging in using a key with this option. IP tunneling is a rarely used option, but can enable full VPN access to the internal network over SSH.

Key Management for OpenSSH

OpenSSH keys are fully supported in Universal SSH Key Manager. It is the leading product for SSH key management.

For general information on SSH key management, see our key management page.

Detailed Description of How to Configure Authorized Keys for OpenSSH (2)

Detailed Description of How to Configure Authorized Keys for OpenSSH (2024)

FAQs

How to setup ssh authorized_keys? ›

Procedure
  1. Use the ssh-keygen tool to create a key pair. ...
  2. Validate that the keys were generated. ...
  3. Enable key-based authentication in the /etc/ssh directory on the SSH server. ...
  4. Copy the rsa. ...
  5. If you have an existing authorized_keys file, edit it to remove any no-pty restrictions.

How to configure key-based authentication for SSH? ›

# How to Set Up SSH Key-Based Authentication for Secure, Password-Less Logins
  1. ## Step 1: Generate a New SSH Key Pair. First, you need to create a new SSH key pair on your client machine. ...
  2. ## Step 2: Configure the SSH Client. ...
  3. ## Step 3: Copy the Public Key to the Server. ...
  4. ## Step 4: Log In Without a Password.
Aug 23, 2023

How does the authorized_keys file work? ›

The authorized_keys file in SSH specifies the SSH keys that can be used for logging into the user account for which the file is configured. It is a highly important configuration file, as it configures permanent access using SSH keys and needs proper management.

What permissions are needed for Authorized_keys in SSH? ›

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 create OpenSSH keys? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How do I add multiple keys in Authorized_Keys? ›

Yes, you can use multiple keys in the authorized_keys file. In the authorized_keys file, add the new key in a new line and then save the file.

How do I specify a key for SSH? ›

To specify which private key should be used for connections to a particular remote host, use a text editor to create a ~/.ssh/config that includes the Host and IdentityFile keywords. Once you save the file, SSH will use the specified private key for future connections to that host.

How does SSH key based authentication work? ›

For key-based authentication, a matched pair of cryptographic key files is generated. The pair consists of a private key and a public key that uniquely identify the user. The private key usually has a permission of 600 and is kept on the local server.

How do I create a valid SSH key? ›

Generating a new SSH key
  1. Open Terminal .
  2. Paste the text below, replacing the email used in the example with your GitHub email address. ssh-keygen -t ed25519 -C "[email protected]" ...
  3. At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."

What is Authorized_keys structure in SSH? ›

ssh. authorized_keys2 . Each line of the file contains one key specification (empty lines and lines starting with # are ignored as comments). Public keys that are not in key rings consist of options, keytype, base64-encoded key, comment.

Where is the OpenSSH authorized key file? ›

Location of the Authorized Keys File

With OpenSSH, the authorized keys are by default configured in . ssh/authorized_keys in the user's home directory. Many OpenSSH versions also look for ssh/authorized_keys2 .

What is the difference between Authorized_keys and authorized_keys2? ›

The $HOME/. ssh/authorized_keys file lists the RSA keys that are permitted for RSA authentication in SSH protocols 1.3 and 1.5 Similarly, the $HOME/. ssh/authorized_keys2 file lists the DSA and RSA keys that are permitted for public key authentication (PubkeyAuthentication) in SSH protocol 2.0.

Who should own the authorized_keys file? ›

This directory should have 755 permissions and be owned by the user. Move the authorized_keys file into it. The authorized_keys file should still have 644 permissions and be owned by the user.

Is authorized_keys public or private in SSH? ›

An authorized key in SSH is a public key used for granting login access to users. The authentication mechanism is called public key authentication. Authorized keys are configured separately for each user - usually in the . ssh/authorized_keys file in the user's home directory.

How to configure SSH public key authentication? ›

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 to setup SSH key Exchange? ›

Configuring SSH key-exchange
  1. Enter global configuration mode. ...
  2. Use the ssh server key-exchange command to set the key exchange algorithm for the server. ...
  3. Use the ssh client key-exchange command to set the key exchange algorithm for the client.

How to activate SSH keys? ›

Generating a new SSH key for a hardware security key
  1. Insert your hardware security key into your computer.
  2. Open Terminal .
  3. Paste the text below, replacing the email address in the example with the email address associated with your account on GitHub. ...
  4. When you are prompted, touch the button on your hardware security key.

How to set up SSH keys in terminal? ›

Creating SSH Keys (Terminal)
  1. Create an .ssh folder in the home directory. Create a .ssh folder in your user account's home directory if it doesn't already exist: $ mkdir /home/<user name>/.ssh. ...
  2. Use ssh-keygen to generate SSH key. ...
  3. Retrieve the public key file. ...
  4. Use the key in an async session.

Where is authorized_keys in SSH server? ›

Location of the Authorized Keys File

With OpenSSH, the authorized keys are by default configured in . ssh/authorized_keys in the user's home directory. Many OpenSSH versions also look for ssh/authorized_keys2 . Some organizations use custom OpenSSH builds with different default paths.

Top Articles
Payment Holiday: Requirements Explained | Pros and Cons
How Paying Bills Can Affect Your Credit Score
Kevin Cox Picks
Voorraad - Foodtrailers
Exam With A Social Studies Section Crossword
Die Windows GDI+ (Teil 1)
Craigslist Free Stuff Appleton Wisconsin
35105N Sap 5 50 W Nit
Craigslist In Fredericksburg
Sunday World Northern Ireland
PGA of America leaving Palm Beach Gardens for Frisco, Texas
Moe Gangat Age
Aita Autism
10-Day Weather Forecast for Florence, AL - The Weather Channel | weather.com
Union Ironworkers Job Hotline
G Switch Unblocked Tyrone
Royal Cuts Kentlands
Erica Banks Net Worth | Boyfriend
What Is Vioc On Credit Card Statement
Is A Daytona Faster Than A Scat Pack
Busted News Bowie County
Where to eat: the 50 best restaurants in Freiburg im Breisgau
Terry Bradshaw | Biography, Stats, & Facts
Vernon Dursley To Harry Potter Nyt Crossword
Raw Manga 1000
Anonib Oviedo
Mdt Bus Tracker 27
Violent Night Showtimes Near Johnstown Movieplex
Aes Salt Lake City Showdown
Kuttymovies. Com
Our 10 Best Selfcleaningcatlitterbox in the US - September 2024
Rush County Busted Newspaper
Missing 2023 Showtimes Near Mjr Southgate
Donald Trump Assassination Gold Coin JD Vance USA Flag President FIGHT CIA FBI • $11.73
Citibank Branch Locations In Orlando Florida
Emiri's Adventures
Roadtoutopiasweepstakes.con
The Menu Showtimes Near Amc Classic Pekin 14
#scandalous stars | astrognossienne
Best Weapons For Psyker Darktide
Grapes And Hops Festival Jamestown Ny
Planet Fitness Santa Clarita Photos
Telugu Moviez Wap Org
Search All of Craigslist: A Comprehensive Guide - First Republic Craigslist
Obituaries in Hagerstown, MD | The Herald-Mail
Pathfinder Wrath Of The Righteous Tiefling Traitor
Amy Zais Obituary
Www.homedepot .Com
Walmart Front Door Wreaths
Superecchll
28 Mm Zwart Spaanplaat Gemelamineerd (U999 ST9 Matte | RAL9005) Op Maat | Zagen Op Mm + ABS Kantenband
Cbs Scores Mlb
Latest Posts
Article information

Author: Annamae Dooley

Last Updated:

Views: 6161

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Annamae Dooley

Birthday: 2001-07-26

Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

Phone: +9316045904039

Job: Future Coordinator

Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.