12.2. Configuring OpenSSH
12.2.1. Configuration Files
ssh, scp, and sftp), and those for the server (the sshd daemon).
/etc/ssh/ directory as described in Table 12.1, “System-wide configuration files”. User-specific SSH configuration information is stored in ~/.ssh/ within the user's home directory as described in Table 12.2, “User-specific configuration files”.
Table 12.1. System-wide configuration files
| File | Description |
|---|---|
/etc/ssh/moduli | Contains Diffie-Hellman groups used for the Diffie-Hellman key exchange which is critical for constructing a secure transport layer. When keys are exchanged at the beginning of an SSH session, a shared, secret value is created which cannot be determined by either party alone. This value is then used to provide host authentication. |
/etc/ssh/ssh_config | The default SSH client configuration file. Note that it is overridden by ~/.ssh/config if it exists. |
/etc/ssh/sshd_config | The configuration file for the sshd daemon. |
/etc/ssh/ssh_host_ecdsa_key | The ECDSA private key used by the sshd daemon. |
/etc/ssh/ssh_host_ecdsa_key.pub | The ECDSA public key used by the sshd daemon. |
/etc/ssh/ssh_host_rsa_key | The RSA private key used by the sshd daemon for version 2 of the SSH protocol. |
/etc/ssh/ssh_host_rsa_key.pub | The RSA public key used by the sshd daemon for version 2 of the SSH protocol. |
/etc/pam.d/sshd | The PAM configuration file for the sshd daemon. |
/etc/sysconfig/sshd | Configuration file for the sshd service. |
Table 12.2. User-specific configuration files
| File | Description |
|---|---|
~/.ssh/authorized_keys | Holds a list of authorized public keys for servers. When the client connects to a server, the server authenticates the client by checking its signed public key stored within this file. |
~/.ssh/id_ecdsa | Contains the ECDSA private key of the user. |
~/.ssh/id_ecdsa.pub | The ECDSA public key of the user. |
~/.ssh/id_rsa | The RSA private key used by ssh for version 2 of the SSH protocol. |
~/.ssh/id_rsa.pub | The RSA public key used by ssh for version 2 of the SSH protocol. |
~/.ssh/known_hosts | Contains host keys of SSH servers accessed by the user. This file is very important for ensuring that the SSH client is connecting to the correct SSH server. |
Warning
Privilege Separation feature by using the UsePrivilegeSeparation no directive in the /etc/ssh/sshd_config file. Turning off Privilege Separation disables many security features and exposes the server to potential security vulnerabilities and targeted attacks. For more information about UsePrivilegeSeparation, see the sshd_config(5) manual page or the What is the significance of UsePrivilegeSeparation directive in /etc/ssh/sshd_config file and how to test it ? Red Hat Knowledgebase article.
ssh_config(5) and sshd_config(5) manual pages.
12.2.2. Starting an OpenSSH Server
sshd daemon in the current session, type the following at a shell prompt as root:
~]# systemctl start sshd.servicesshd daemon in the current session, use the following command as root:
~]# systemctl stop sshd.serviceroot:
~]# systemctl enable sshd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.sshd daemon depends on the network.target target unit, which is sufficient for static configured network interfaces and for default ListenAddress 0.0.0.0 options. To specify different addresses in the ListenAddress directive and to use a slower dynamic network configuration, add dependency on the network-online.target target unit to the sshd.service unit file. To achieve this, create the /etc/systemd/system/sshd.service.d/local.conf file with the following options:
[Unit] Wants=network-online.targetAfter=network-online.target
systemd manager configuration using the following command:
~]# systemctl daemon-reload@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key has just been changed.
/etc/ssh/ directory. See Table 12.1, “System-wide configuration files” for a complete list, and restore the files whenever you reinstall the system.
12.2.3. Requiring SSH for Remote Connections
telnet, rsh, rlogin, and vsftpd.
vsftpd service, see Section 16.2, “FTP”. To learn how to manage system services in Red Hat Enterprise Linux 7, read Chapter 10, Managing Services with systemd.
12.2.4. Using Key-based Authentication
/etc/ssh/sshd_config configuration file in a text editor such as vi or nano, and change the PasswordAuthentication option as follows:
PasswordAuthentication no
PubkeyAuthentication no has not been set. If connected remotely, not using console or out-of-band access, testing the key-based log in process before disabling password authentication is advised.
ssh, scp, or sftp to connect to the server from a client machine, generate an authorization key pair by following the steps below. Note that keys must be generated for each user separately.
use_nfs_home_dirs SELinux boolean first:
~]# setsebool -P use_nfs_home_dirs 1Important
root, only root will be able to use the keys.
Note
~/.ssh/ directory. After reinstalling, copy it back to your home directory. This process can be done for all users on your system, including root.
12.2.4.1. Generating Key Pairs
- Generate an RSA key pair by typing the following at a shell prompt:
~]$
ssh-keygen -t rsaGenerating public/private rsa key pair. Enter file in which to save the key (/home/USER/.ssh/id_rsa): - Press Enter to confirm the default location,
~/.ssh/id_rsa, for the newly created key. - Enter a passphrase, and confirm it by entering it again when prompted to do so. For security reasons, avoid using the same password as you use to log in to your account.After this, you will be presented with a message similar to this:
Your identification has been saved in /home/USER/.ssh/id_rsa. Your public key has been saved in /home/USER/.ssh/id_rsa.pub. The key fingerprint is: SHA256:UNIgIT4wfhdQH/K7yqmjsbZnnyGDKiDviv492U5z78Y USER@penguin.example.com The key's randomart image is: +---[RSA 2048]----+ |o ..==o+. | |.+ . .=oo | | .o. ..o | | ... .. | | .S | |o . . | |o+ o .o+ .. | |+.++=o*.o .E | |BBBo+Bo. oo | +----[SHA256]-----+
Note
To get an MD5 key fingerprint, which was the default fingerprint in previous versions, use thessh-keygencommand with the-E md5option. - By default, the permissions of the
~/.ssh/directory are set torwx------or700expressed in octal notation. This is to ensure that only the USER can view the contents. If required, this can be confirmed with the following command:~]$
ls -ld ~/.sshdrwx------. 2 USER USER 54 Nov 25 16:56 /home/USER/.ssh/ - To copy the public key to a remote machine, issue a command in the following format:
This will copy the most recently modifiedssh-copy-id user@hostname~/.ssh/id*.pubpublic key if it is not yet installed. Alternatively, specify the public key's file name as follows:
This will copy the content ofssh-copy-id -i~/.ssh/id_rsa.pubuser@hostname~/.ssh/id_rsa.pubinto the~/.ssh/authorized_keysfile on the machine to which you want to connect. If the file already exists, the keys are appended to its end.
- Generate an ECDSA key pair by typing the following at a shell prompt:
~]$
ssh-keygen -t ecdsaGenerating public/private ecdsa key pair. Enter file in which to save the key (/home/USER/.ssh/id_ecdsa): - Press Enter to confirm the default location,
~/.ssh/id_ecdsa, for the newly created key. - Enter a passphrase, and confirm it by entering it again when prompted to do so. For security reasons, avoid using the same password as you use to log in to your account.After this, you will be presented with a message similar to this:
Your identification has been saved in /home/USER/.ssh/id_ecdsa. Your public key has been saved in /home/USER/.ssh/id_ecdsa.pub. The key fingerprint is: SHA256:8BhZageKrLXM99z5f/AM9aPo/KAUd8ZZFPcPFWqK6+M USER@penguin.example.com The key's randomart image is: +---[ECDSA 256]---+ | . . +=| | . . . = o.o| | + . * . o...| | = . . * . + +..| |. + . . So o * ..| | . o . .+ = ..| | o oo ..=. .| | ooo...+ | | .E++oo | +----[SHA256]-----+
- By default, the permissions of the
~/.ssh/directory are set torwx------or700expressed in octal notation. This is to ensure that only the USER can view the contents. If required, this can be confirmed with the following command:~]$
ls -ld ~/.ssh~]$ ls -ld ~/.ssh/ drwx------. 2 USER USER 54 Nov 25 16:56 /home/USER/.ssh/ - To copy the public key to a remote machine, issue a command in the following format:
This will copy the most recently modifiedssh-copy-id USER@hostname~/.ssh/id*.pubpublic key if it is not yet installed. Alternatively, specify the public key's file name as follows:
This will copy the content ofssh-copy-id -i~/.ssh/id_ecdsa.pubUSER@hostname~/.ssh/id_ecdsa.pubinto the~/.ssh/authorized_keyson the machine to which you want to connect. If the file already exists, the keys are appended to its end.
Important
12.2.4.2. Configuring ssh-agent
ssh-agent authentication agent. If you are running GNOME, you can configure it to prompt you for your passphrase whenever you log in and remember it during the whole session. Otherwise you can store the passphrase for a certain shell prompt.
- Make sure you have the openssh-askpass package installed. If not, see Section 9.2.4, “Installing Packages” for more information on how to install new packages in Red Hat Enterprise Linux.
- Press the Super key to enter the Activities Overview, type
Startup Applicationsand then press Enter. The Startup Applications Preferences tool appears. The tab containing a list of available startup programs will be shown by default. The Super key appears in a variety of guises, depending on the keyboard and other hardware, but often as either the Windows or Command key, and typically to the left of the Space bar.
Figure 12.1. Startup Applications Preferences
- Click the button on the right, and enter
/usr/bin/ssh-addin the Command field.
Figure 12.2. Adding new application
- Click and make sure the checkbox next to the newly added item is selected.

Figure 12.3. Enabling the application
- Log out and then log back in. A dialog box will appear prompting you for your passphrase. From this point on, you should not be prompted for a password by
ssh,scp, orsftp.
Figure 12.4. Entering a passphrase
~]$ ssh-add
Enter passphrase for /home/USER/.ssh/id_rsa:
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.