Configure OpenSSH authentication
Protect remote login sessions from eavesdropping by configuring SSH key-based and smart card authentication methods.
SSH and OpenSSH Copy linkLink copied!
SSH (Secure Shell) is a program for remote machine login and command execution. The SSH protocol provides encrypted communication between two untrusted hosts over an insecure network. You can also forward X11 connections and arbitrary TCP/IP ports over the secure channel.
The SSH protocol reduces security threats when you use it for remote shell login or file copying. It prevents interception of communication between two systems. It also prevents impersonation of a particular host.
The SSH client and server use digital signatures to verify their identities. All communication between the client and server systems is encrypted.
A host key authenticates hosts in the SSH protocol. Host keys are cryptographic keys. They are generated automatically when OpenSSH starts for the first time or when the host boots for the first time.
OpenSSH is an implementation of the SSH protocol supported by Linux, UNIX, and similar operating systems. It includes the core files necessary for both the OpenSSH client and server. The OpenSSH suite consists of the following user-space tools:
sshis a remote login program (SSH client).sshdis an OpenSSH SSH daemon.scpis a secure remote file copy program.sftpis a secure file transfer program.ssh-agentis an authentication agent for caching private keys.ssh-addadds private key identities tossh-agent.ssh-keygengenerates, manages, and converts authentication keys forssh.ssh-copy-idis a script that adds local public keys to theauthorized_keysfile on a remote SSH server.ssh-keyscangathers SSH public host keys.
For more information, use the man -k ssh command.
In RHEL 9 and later, SFTP replaces SCP by default. SCP has security issues such as CVE-2020-15778.
You can force the use of the original SCP/RCP protocol if SFTP is unavailable or incompatible in your scenario. Use the scp command with the -O option.
The OpenSSH suite in RHEL supports only SSH version 2. It has an enhanced key-exchange algorithm. This algorithm is not vulnerable to exploits known in the older version 1.
Red Hat Enterprise Linux includes the openssh, openssh-server, and openssh-clients packages. These OpenSSH packages require the OpenSSL package openssl-libs. This package contains cryptographic libraries for securing data exchange.
OpenSSH is one of the core cryptographic subsystems of RHEL. It uses system-wide cryptographic policies. This ensures that weak cipher suites and cryptographic algorithms are disabled in the default configuration.
To modify the policy, you can:
- Use the
update-crypto-policiescommand to adjust the settings. - Manually opt out of the system-wide cryptographic policies.
The OpenSSH suite uses two sets of configuration files. One set is for client programs (ssh, scp, and sftp). Another set is for the server (the sshd daemon).
System-wide SSH configuration information is stored in the /etc/ssh/ directory. The /etc/ssh/ssh_config file contains the client configuration. The /etc/ssh/sshd_config file is the default OpenSSH server configuration file.
User-specific SSH configuration information is stored in ~/.ssh/. For a detailed list of OpenSSH configuration files, see the FILES section in the sshd(8) man page on your system.
Generate SSH key pairs Copy linkLink copied!
Generate an SSH key pair on your local system and copy the public key to the OpenSSH server to enable password-free login. Each user who wants to create a key must run this procedure.
Before you begin Copy linkLink copied!
- You are logged in as a user who wants to connect to the OpenSSH server by using keys.
- The OpenSSH server is configured to allow key-based authentication.
About this task Copy linkLink copied!
To preserve generated key pairs after you reinstall the system, back up the ~/.ssh/ directory before you create new keys. After reinstalling, copy it back to your home directory. You can do this for all users on your system, including root.
Procedure Copy linkLink copied!
Results Copy linkLink copied!
- Log in to the OpenSSH server by using the key file:
$ ssh -o PreferredAuthentications=publickey <username>@<ssh-server-example.com>
Set key-based authentication as the only method on an OpenSSH server Copy linkLink copied!
To improve system security, enforce key-based authentication by disabling password authentication on your OpenSSH server.
Before you begin Copy linkLink copied!
- The
openssh-serverpackage is installed. - The
sshddaemon is running on the server. - You can already connect to the OpenSSH server by using a key.
See the Generating SSH key pairs section for details.
About this task Copy linkLink copied!
If you disable password authentication without ensuring that key-based authentication works correctly, you can lock yourself out of the server. Test your SSH key authentication thoroughly before applying this configuration, and keep a current session open while testing to revert changes if necessary.
Procedure Copy linkLink copied!
Results Copy linkLink copied!
- Confirm that password authentication is disabled:
# sshd -T | grep -i passwordauthenticationpasswordauthentication no - Confirm that keyboard-interactive authentication is disabled:
# sshd -T | grep -i kbdinteractiveauthenticationkbdinteractiveauthentication no - From a different system, attempt to connect using password authentication to verify it is rejected:
$ ssh -o PreferredAuthentications=password <username>@<server><username>@<server>: Permission denied (publickey).The connection is rejected because only public key authentication is allowed.
Authenticate by SSH keys stored on a smart card Copy linkLink copied!
Use SSH keys stored on a smart card for authentication to add a physical layer of protection to your credentials. This method provides enhanced security against unauthorized access.
Before you begin Copy linkLink copied!
- On the client side, the
openscpackage is installed and thepcscdservice is running.
About this task Copy linkLink copied!
You can create and store ECDSA and RSA keys on a smart card and authenticate by the smart card on an OpenSSH client. Smart-card authentication replaces the default password authentication.