This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

SSH

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page SSH and the translation is 34% complete.
Outdated translations are marked like this.
Resources

SSH (Secure SHell) est un programme de terminal chiffré qui remplace telnet , l'outil classique des systèmes d'exploitation du type Unix.

In addition to remote terminal access provided by the main ssh binary, the SSH suite of programs has grown to include other tools such as scp (Secure Copy Program) and sftp (Secure File Transfer Protocol).

À l'origine, SSH n'était pas libre. Cependant, de nos jours, la mise en œuvre la plus populaire de SSH, qui constitue un standard de fait, est l'OpenSSH de OpenBSD. Cette version est pré-installée sur Gentoo.

Installation

Vérifier l'installation

Most deployments of Gentoo Linux will already have OpenSSH installed on the system. This can be checked by running the ssh command. If it is installed a usage statement should be printed:

user $ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port]
           [-Q cipher | cipher-auth | mac | kex | key]
           [-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] [user@]hostname [command]

If no usage statement is printed ssh is either corrupted or not installed. It is also possible that a user is simply rebuilding OpenSSH to include a new USE configuration. Whatever the case, proceed on to view possible USE settings.

Options de la variable USE

USE flags for net-misc/openssh Port of OpenBSD's free SSH release

audit Enable support for Linux audit subsystem using sys-process/audit
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
kerberos Add kerberos support
ldns Use LDNS for DNSSEC/SSHFP validation.
libedit Use the libedit library (replacement for readline)
livecd Enable root password logins for live-cd environment.
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip
pie Build programs as Position Independent Executables (a security hardening technique)
security-key Include builtin U2F/FIDO support
selinux  !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
ssl Enable additional crypto algorithms via OpenSSL
static  !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
verify-sig Verify upstream signatures on distfiles
xmss Enable XMSS post-quantum authentication algorithm

Emerge

Une fois les paramètres USE changés, n'oubliez pas d'installer (ou de recompiler) OpenSSH.

root #emerge --ask --changed-use net-misc/openssh

Configuration

Créer des clés

Pour vous fournir un shell sécurisé, des clés de chiffrage sont utilisées pour le chiffrage, le déchiffrage et les fonctionnalités de hâchage offertes par SSH.

On the first start of the SSH service, system keys will be generated. Keys can be (re)generated using the ssh-keygen command.

Pour générer les clés les clés pour la version 2 du protocole SSH (algorythmes DSA et RSA):

root #/usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N "PassphraseSecrete"
root #/usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "PassphraseSecrete"

The article Secure Secure Shell suggests using Ed25519 and RSA public key algorithms with:

root #/usr/bin/ssh-keygen -t ed25519 -a 100 -f /etc/ssh/ssh_host_dsa_key -N ""
root #/usr/bin/ssh-keygen -t rsa -b 4096 -o -a 100 -f /etc/ssh/ssh_host_rsa_key -N ""

Configuration du serveur

Le serveur SSH est ordinairement configuré dans le fichier /etc/ssh/sshd_config, bien qu'il soit aussi possible de compléter la configuration dans le fichier /etc/conf.d/sshd d'OpenRC, y compris le changement de l'emplacement du fichier de configuration. Pour une information détaillée sur la manière de configurer le serveur, reportez-vous à la page de manuel de sshd_config.

Les utilisateurs cherchant une configuration centrée sur la sécurité devraient se référer guide de Sven.

Configuration du client

The ssh client and related programs (scp, sftp, etc.) can be configured using the following files:

  • ~/.ssh/config
  • /etc/ssh/ssh_config

Pour une information plus complète reportez-vous à la page de manuel ssh_config:

user $man ssh_config

Passwordless authentication

Pratique pour la gestion du serveur git.

Client

Sur votre client, exécutez :

user $ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/larry/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/larry/.ssh/id_rsa.
Your public key has been saved in /home/larry/.ssh/id_rsa.pub.
The key fingerprint is:
de:ad:be:ef:15:g0:0d:13:37:15:ad:cc:dd:ee:ff:61 larry@client
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|     .           |
| . .. n   .      |
|   . (: . .      |
|  o   . . : .    |
| . ..: >.> .     |
|  * ?. .         |
| o.. .. ..       |
| :. .  ! ).       |
+-----------------+

Serveur

Make sure an account for the user exists on the server, and then place the clients' id_rsa.pub file into the server's ~/.ssh/authorized_keys file in the user's home directory. This can be done by running the following command on the client computer (here, the user's passphrase on the server needs to be entered):

user $ssh-copy-id <server>
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/larry/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
larry@<server>'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '<server>'"
and check to make sure that only the key(s) you wanted were added.

Afterwards a passwordless login should be possible doing

user $ssh <server>
larry@<server>

Then on the server, the file /etc/ssh/sshd_config should be set to PasswordAuthentication no.

Single machine testing

La procédure mentionnée ci-dessus peut être testée localement :

user $ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/larry/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
...
user $mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
user $ssh localhost

Intrusion prevention

SSH is a commonly attacked service. Tools such as sshguard and fail2ban monitor logs and black list remote users who have repeatedly attempted, yet failed to login. Utilize them as needed to secure a frequently attacked system.

Usage

Services

OpenRC

Add the OpenSSH daemon to the default runlevel:

root #rc-update add sshd default

Start the sshd daemon with:

root #rc-service sshd start

The OpenSSH server can be controlled like any other OpenRC-managed service:

root #rc-service sshd start
root #rc-service sshd stop
root #rc-service sshd restart
Note
Active SSH connections to the server remain unaffected when issuing rc-service sshd restart.

systemd

To have the OpenSSH daemon start when the system starts:

root #systemctl enable sshd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib64/systemd/system/sshd.service.

To start the OpenSSH daemon now:

root #systemctl start sshd.service

To check if the service has started:

root #systemctl status sshd.service

Escape sequences

During an active SSH session, pressing the tilde (~) key starts an escape sequence. Enter the following for a list of options:

ssh>~?

Troubleshooting

There are 3 different levels of debug modes that can help troubleshooting issues. With the -v option SSH prints debugging messages about its progress. This is helpful in debugging connection, authentication, and configuration problems. Multiple -v options increase the verbosity. Maximum verbosity is three levels deep.

user $ssh example.org -v
user $ssh example.org -vv
user $ssh example.org -vvv

Death of long-lived connections

Many internet access devices perform Network Address Translation (NAT), a process that enables devices on a private network such as that typically found in a home or business place to access foreign networks, such as the internet, despite only having a single IP address on that network. Unfortunately, not all NAT devices are created equal, and some of them incorrectly close long-lived, occasional-use TCP connections such as those used by SSH. This is generally observable as a sudden inability to interact with the remote server, even though the ssh client program has not exited.

In order to resolve the issue, OpenSSH clients and servers can be configured to send a 'keep alive', or invisible message aimed at maintaining and confirming the live status of the link:

  • To enable keep alive for all clients connecting to your local server, set ClientAliveInterval 30 (or some other value, in seconds) within the /etc/ssh/sshd_config file.
  • To enable keep alive for all servers connected to by your local client, set ServerAliveInterval 30 (or some other value, in seconds) within the /etc/ssh/ssh_config file.

X11 forwarding, not forwarding, or tunneling

Problem: After having made the necessary changes to the configuration files for permitting X11 forwarding, it is discovered X applications are executing on the server and are not being forwarded to the client.

Solution: What is likely occurring during SSH login into the remote server or host, the DISPLAY variable is either being unset or is being set after the SSH session sets it.

Test for this scenario perform the following after logging in remotely:

user $echo $DISPLAY
localhost:10.0

The output should be something similar to localhost:10.0 or localhost2.local:10.0 using server side X11UseLocalhost no setting. If the usual :0.0 is not displayed, check to make sure the DISPLAY variable within ~/.bash_profile is not being unset or re-initializing. If it is, remove or comment out any custom initialization of the DISPLAY variable to prevent the code in ~/.bash_profile from executing during a SSH login:

user $ssh -t larry@localhost2 bash --noprofile

Be sure to substitute larry in the command above with the proper username.

A trick that works to complete this task would be to define an alias within the users' ~/.bashrc file.

See also

External resources