SSH/en

SSH (Secure SHell) is an encrypted terminal program that replaces the classic telnet tool on Unix-like operating systems.

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) and sftp (secure file transfer protocol).

Originally, SSH was not free. However, today the most popular and de-facto standard implementation of SSH is OpenBSD's OpenSSH, which comes pre-installed on Gentoo.

Check install
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:

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.

Emerge OpenSSH
After changing the necessary USE flags, do not forget to install (or rebuild) OpenSSH:

Server
Add openssh to the default runlevel if this hasn't been done already.

Start sshd daemon with:

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

Create Keys
In order to provide a secure shell, cryptographic keys are used to manage the encryption, decryption and hashing functionalities offered by SSH.

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

To generate the key used for SSH protocol version 1 (which usually is not enabled anymore as it has been deprecated in favor of protocol version 2):

To generate the keys for SSH protocol version 2 (DSA and RSA algorithms):

Server configuration
The SSH server is usually configured in the file, though it is also possible to perform further configuration in OpenRC's, including changing the location of the configuration file. For detailed information on how to configure the server see the sshd_config man page.

You should also study this guide for a security focused configuration.

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

For more information read the  manual:

Passwordless Authentication
Handy for git server management.

Client
On the client run the following command:

Server
Make sure an account for the user exists on the server, and then place the clients' file into the  file.

Single machine testing
The above procedure can be tested out locally:

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

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, 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 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 file.

X11 Forwarding Not Forwarding or Tunneling!
Problem: After you have made the necessary changes to the configuration files for permitting X11 Forwarding, you find 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  variable is either being unset or is being set after the SSH session sets it.

Test for this scenario as follows after logging in remotely:

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

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

Intrusion Prevention
ssh is a commonly attacked service. sshguard & fail2ban monitor logs and black list remote users who have repeatedly failed to login.

External resources

 * Securing OpenSSH - Gentoo developer documentation.
 * OpenSSH Key Management Part1 - Gentoo documentation, have a look at all 3 parts.