SSH

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 (in very common use) and sftp (less common).

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

Installation
Install :

Server
The OpenSSH server can be controlled like any other OpenRC-managed service, with

Note that active connections to the server remain unaffected when issuing /etc/init.d/sshd restart, whereas running /etc/init.d/sshd stop followed by /etc/init.d/sshd start may cause disconnection.

Create Keys
The following commands will generate new keys:

where -N "" is the passphrase. With "" it's empty. If you require one, put your phrase into it.

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 former. 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.) are configured in the file.

For more information on how to configure these programs read the manual:

Passwordless Authentication
Handy for git server management

Client
On the client run

Follow further instructions. After successful key generation move the generated  to the server user your logging in as ~/.ssh/authorized_keys

Server
useradd a user

then place clients id_rsa.pub file into the new users

Single Machine Testing
enter 5 times

Troubleshooting
There are 3 different levels of debug modes. -v Causes ssh to print 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.

debug1 mode:

debug2 mode:

debug3 mode:

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 $DISPLAY variable is either being unset or is being set after the SSH session sets it. Test for this scenario by doing "echo $DISPLAY" within the remote shell and you should get something similar to "localhost:10.0" or "localhost2.local:10.0" using server side "X11UseLocalhost no" setting. If you're getting the usual ":0.0", check to make sure you are not unsetting or initializing the $DISPLAY variable within $HOME/.bash_profile. And if so, remove or comment your custom initialization of $DISPLAY or prevent bash_profile from executing during SSH login using "ssh -t me@localhost2 bash --noprofile". (Can alias this within bashrc.)