Red Hat Certified System Administration 8



Chapter 20: Configuring SSH


Goal

To configure secure command-line access on remote systems using Open SSH.

Sommaire

  • Accessing remote prompt
  • SSH host keys
  • Configuring SSH Key-based Authentication
  • Customizing SSH Service Configuration


Accessing remote prompt



SSH host keys



Configuring SSH Key-based Authentication


Configuring SSH Key-based Authentication

Les utilisateurs peuvent authentifier les connexions SSH sans mot de passe en utilisant l'authentification par clé publique. Ssh permet aux utilisateurs de s'authentifier à l'aide d'un schéma de clé public-privé. Cela signifie que deux clés sont générées, une clé privée et une clé publique. Le fichier de clé privée est utilisé comme authentification, informations d'identification, et comme un mot de passe, doit être gardé secret et sécurisé. La clé publique est copiée dans les systèmes sur lesquels l'utilisateur veut se connecter, et est utilisé pour vérifier la clé privée. La clé publique n'a pas besoin d'être secrète. Un serveur SSH disposant de la clé publique peut lancer un défi qui ne peut être géré que par un système contenant votre clé privée. Par conséquent, vous pouvez vous authentifier en utilisant la présence de votre clé. Cela vous permet d'accéder aux systèmes d'une manière qui ne nécessite pas de taper un mot de passe à chaque fois, mais qui reste sécurisée.




  1. Ensure for Key Based Authentication configuration on server

    /etc/ssh/sshd_config PubkeyAuthentication yes


  2. Keys generation

    Keys generation is done using the ssh-keygen command. This generates
    • the private key ~/.ssh/id_rsa
    • the public key ~/.ssh/id_rsa.pub
    You can generate keys with or without passphrase. Generate keys without passphrase is useful for automation actions (Just enter when prompt asks you for passphrase)

    Once the SSH keys have been generated, they are stored by default in the .ssh/ directory of your home directory. Permissions should be 600 on the private key and 644 on the public key.




  3. Check your keys

    Comparer les empreintes des clés
    Pour confirmer qu'une clé publique est valide et correspond à une clé privée, comparez leurs empreintes :

    - Empreinte de la clé privée
    # ssh-keygen -lf ~/.ssh/id_rsa

    - Empreinte de la clé publique
    # ssh-keygen -lf ~/.ssh/id_rsa.pub

    Si les empreintes sont identiques, la clé privée correspond bien à la clé publique.


  4. Copy key to SSH Server system user

    Before key-based authentication can be used, the public key needs to be copied to the Destination system. This can be done with ssh-copy-id.

    # ssh-copy-id remote-user@remote-host
    When the key is copied to another system using ssh-copy-id, it copies the ~/.ssh/id_rsa.pub file by default.

    On Server authorized connections keys are stored in ~/.ssh/authorized_keys file


  5. Initiate your ssh connection

    # ssh remote-user@remote-host -i pub_key_file


Customizing SSH Service Configuration


Customizing SSH Service Configuration

The OpenSSH server configuration file

While Open SSH server configuration usually does not require modification, additional security measures are available.
Various aspects of the Open SSH server can be modified in the configuration file /etc/ssh/sshd_config.

Prohibit the root user from logging in using SSH

From a security stand point. It is advisable to prohibit the root user from directly logging in to the system with ssh.
The user name root exists on every Linux system by default, so a potential attacker only has to guess the password, instead of a valid username and password combination.
The root user has unrestricted privileges.

PermitRootLogin no

Prohibit password authentication using SSH

Only allowing key-based logins to the remote command line has various advantages:

  • SSH keys are longer than an average password, which adds security.
  • Less effort to initiate remote shell access after the initial setup.
To prevent password authentication, the PasswordAuthentication option has to be set to no and the ssh service needs to be restarted
PasswordAuthentication no


/etc/ssh/sshd_config

# Comments

PasswordAuthentication yes-or-no # yes to permit user password authenfitication, no to deny user password authenfitication, authorize only key-based Authentication

PermitRootLogin yes-or-no # yes to permit login with root account, no to deny login with root account

MaxSessions n # used to tune the maximum number of sessions that can be open at the same time. Default value is 10


Eninam BAGNABANA     |         |     bagnadavid@outlook.fr     |