keepcalculator

06 Numbers and Powers

Configure SSH Passwordless Login on RHEL

Card No. 06·37195 · Updated · Standard formula, shown below

To configure passwordless SSH login on RHEL, create an SSH key pair on the client, copy its public key to the RHEL account’s ~/.ssh/authorized_keys file, and verify that key-based authentication works. This removes the need to type the account password for each SSH connection; it does not remove the need to protect the private key or keep account access secure.

How SSH key login works

SSH public-key authentication uses a mathematically related pair of keys. The private key stays on the computer initiating the connection, while the matching public key is installed on the RHEL server. During login, SSH checks that the client can use the private key corresponding to an authorized public key. The private key itself is not sent to the server.

“Passwordless” usually means that SSH no longer asks for the remote account’s password. If the private key is protected with a passphrase, you may still be asked for that passphrase when using it. An SSH agent can cache an unlocked key for a session, avoiding repeated passphrase prompts without storing the key unprotected.

1. Check the RHEL account and SSH service

You need a working account on the RHEL host and network access to it. From the client, first confirm ordinary SSH connectivity, substituting the correct username and server name or address:

ssh user@server.example.com

If the server uses a nonstandard SSH port, specify it with -p, for example ssh -p 2222 user@server.example.com. On the server, the OpenSSH server package and service must be available. An administrator can check the service with:

sudo systemctl status sshd

If the service is not installed or running, an administrator may need to install the distribution’s OpenSSH server package and start or enable sshd. RHEL systems commonly use SELinux and firewalld; do not disable either as a shortcut. A server administrator should ensure the SSH service is permitted by the active firewall configuration and that SELinux remains in its normal enforcing mode.

2. Create a key pair on the client

Run key-generation commands on the computer from which you will connect, not on the RHEL server. A common modern choice is Ed25519:

ssh-keygen -t ed25519 -C "yourname@client"

At the prompts, choose the default file location unless you have a reason to keep multiple keys separately. Set a strong passphrase for better protection if the client device or key file could be exposed. The command creates a private key, typically ~/.ssh/id_ed25519, and a public key ending in .pub, typically ~/.ssh/id_ed25519.pub.

  • Never copy or send the private key to the server. Only the public key belongs in authorized_keys.
  • If a key already exists, avoid overwriting it without checking what uses it. Choose a different filename when creating an additional key.
  • Use ssh-keygen -t rsa -b 3072 only where compatibility requirements call for RSA; do not use obsolete algorithms just to work around a configuration issue without checking the server’s supported settings.

3. Install the public key on RHEL

When available, ssh-copy-id is the straightforward way to append the public key to the remote account:

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.com

It normally asks for the account password once so it can install the key. For a custom port, use ssh-copy-id -p 2222 -i ~/.ssh/id_ed25519.pub user@server.example.com. If ssh-copy-id is unavailable, connect using an existing authorized method and add the contents of the public-key file to the account’s ~/.ssh/authorized_keys. For example, display the public key on the client with cat ~/.ssh/id_ed25519.pub, then paste the complete single line into the remote file.

On the RHEL host, the account’s home directory and SSH files must be owned by that account and not writable by other users. Typical permissions are:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Run these commands as the target account, or use an administrator to correct ownership and permissions if necessary. The home directory should not be writable by group or other users. OpenSSH may refuse keys when ownership or permissions are too permissive. Do not change the entire home directory’s permissions blindly; inspect ownership and access requirements first.

4. Test the key before changing passwords

Open a new terminal and test a normal connection:

ssh user@server.example.com

If you specified a custom key filename or have several keys, name it explicitly with -i:

ssh -i ~/.ssh/id_ed25519 user@server.example.com

For useful diagnostic detail, try ssh -v user@server.example.com. Look for messages indicating which key was offered and whether the server accepted it. Keep your current working session open while testing, especially when administering a remote server, so you do not accidentally lock yourself out.

Common failures and checks

  • Wrong account or host: The public key must be in the home directory of the account named in the SSH command. Check the username, hostname, port, and key path.
  • Bad permissions or ownership: Check ~/.ssh, authorized_keys, and the home directory. Correct ownership and restrictive permissions rather than making files more permissive.
  • Key not offered: Use -i to select the intended private key. If using an agent, ssh-add -l lists keys currently loaded; ssh-add ~/.ssh/id_ed25519 can add one.
  • Public key pasted incorrectly: Each key should remain one complete line, including its key type and encoded data. Avoid line breaks introduced by copying or editing.
  • Server policy or configuration: The server may restrict public-key authentication, account access, or permitted key types. An administrator can inspect effective SSH settings and service logs. Configuration changes should be checked and applied carefully; preserve an existing access path until a new connection is verified.
  • Network or firewall issue: If SSH cannot connect at all, key setup is not the first problem. Check the hostname, route, port, service status, and firewall access with the server administrator.

Passphrases, agents, and safer administration

A passphrase protects a private key stored on disk if someone obtains the file. On a desktop, ssh-agent can hold an unlocked key temporarily; run ssh-add to load it when needed. Agent behavior depends on the operating system and session, so do not assume a key remains available after logout or reboot.

Do not disable password authentication immediately after adding a key unless you control the server and have tested a separate key-based session. In managed environments, administrators may require a particular key algorithm, centrally managed access, or multifactor authentication. Follow the system’s access policy. Passwordless key login is an authentication method, not a reason to share accounts or leave private keys unprotected.

Frequently Asked Questions

Does passwordless SSH mean there is no password anywhere?
It means the server account password is not required for that key-authenticated connection. A key passphrase may still be required, and other server operations can still ask for credentials.

Where do I put the SSH public key on RHEL?
Put it in the target account’s ~/.ssh/authorized_keys file. Confirm that the file and directory are owned by the account and have appropriately restrictive permissions.

Can I use the same SSH key for several RHEL servers?
Technically, the same public key can be installed in multiple accounts or servers. Separate keys can make access easier to manage and revoke; follow your organization’s policy and keep private keys private.

Why does SSH still ask me for a password?
It may be asking for the key’s passphrase rather than the account password. If it is the account password, check the username, selected key, public-key installation, permissions, and server policy; ssh -v can help identify where authentication fails.

Is it safe to turn off SSH password authentication?
It can reduce password-based login exposure, but only do so when authorized and after confirming that key access works in a separate session and an appropriate recovery method exists. A misconfiguration can prevent remote access.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →