SSH/ja

SSH (Secure SHell) は、telnet ツールを置き換える、暗号化ターミナルプログラムです. ]]

主要な バイナリが提供するリモートターミナルアクセスに加えて、SSH プログラムスイートには  (Secure Copy Program) や  (Secure File Transfer Protocol) といったその他のツールも含まれるようになっています.

もともと、SSH はフリーではありませんでした. しかしながら、現在最も広く使われているデファクトスタンダードな SSH の実装は Gentoo でもプリインストールされている OpenBSD の OpenSSH です.

インストールの確認
Gentoo Linux のほとんどにおいては、OpenSSH が既にシステムにインストールされています. これは ssh コマンドを実行すれば確認できます. インストール済みなら使い方の文章が出力されるはずです:

使い方が出力されない場合、 が壊れているか、またはインストールされていません. また、新しい USE フラグを導入するために OpenSSH を単に再ビルドすることもできます. いずれにせよ、使用可能な USE 設定を見てみましょう.

Emerge
必要な USE フラグを変更した後には、OpenSSH をインストール(または再ビルド)するのを忘れないでください:

鍵の作成
安全なシェルを提供するために、暗号鍵が SSH の提供する暗号化、復号化、ハッシュといった機能の管理に使われています.

SSH サービスの初回起動時には、システム鍵が生成されます. 鍵は コマンドを使って(再)生成することができます.

SSH プロトコルバージョン2用の鍵(DSA および RSA アルゴリズム)を生成するには:

Secure Secure Shell の記事では Ed25519 および RSA 公開鍵アルゴリズムの使用が推奨されています:

サーバーの設定
SSH サーバーは設定ファイルの位置変更も含め OpenRC の で設定することもできますが、通常は  ファイルで設定されます. サーバーを設定する方法についての詳細は sshd_config の man page を参照してください.

セキュリティーに主眼をおいた設定をするために の OpenSSH ガイドを読むことをおすすめします.

クライアントの設定
クライアントや関連プログラム(、 など)は以下のファイルを使って設定できます:



For more information read the manual:

Passwordless authentication
Handy for git server management.

Client
On the client, if not already done, create a key pair. This can be done by running the following command (of course, not entering a passphrase):

Server
Make sure an account for the user exists on the server, and then place the clients' file into the server's  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):

Afterwards a passwordless login should be possible doing

Then on the server, the file should be set to.

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

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.

OpenRC
Add the OpenSSH daemon to the default runlevel:

Start the sshd daemon with:

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

systemd
To have the OpenSSH daemon start when the system starts:

To start the OpenSSH daemon now:

To check if the service has started:

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

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

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 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  (or some other value, in seconds) within the  file.
 * To enable keep alive for all servers connected to by your local client, set  (or some other value, in seconds) within the  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:

The output should be something similar to  or   using server side   setting. If the usual  is not displayed, check to make sure the DISPLAY variable within  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 from executing during a SSH login:

Be sure to substitute  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' file.

参考

 * Securing the SSH service (Security Handbook)
 * Gentoo Handbook — Installation — Starting the SSH daemon
 * Sakaki%27s_EFI_Install_Guide/Setting_Up_Networking_and_Connecting_via_ssh
 * Gentoo Handbook — Installation — Starting the SSH daemon
 * Sakaki%27s_EFI_Install_Guide/Setting_Up_Networking_and_Connecting_via_ssh
 * Gentoo Handbook — Installation — Starting the SSH daemon
 * Sakaki%27s_EFI_Install_Guide/Setting_Up_Networking_and_Connecting_via_ssh
 * Sakaki%27s_EFI_Install_Guide/Setting_Up_Networking_and_Connecting_via_ssh

外部の情報

 * Securing OpenSSH - Gentoo developer documentation.
 * — SSH Proxy Command -- connect.c
 * https://lonesysadmin.net/2011/11/08/ssh-escape-sequences-aka-kill-dead-ssh-sessions/amp/ - A blog entry on escape sequences.
 * https://hackaday.com/2017/10/18/practical-public-key-cryptography/ - Practical public key cryptography (Hackaday).
 * SSH on wiki.archlinux.org