sshd (Secure Shell Daemon) サービスは、Linux 用の OpenSSH 実装の一部であり、認証されたエンドツーエンドの暗号化されたネットワーク通信を提供します。たとえば、共有鍵情報の交換などの代替認証技術を使用するように sshd サービスを構成できるため、あるホストのユーザーはパスワードを使用せずに別のシステムにログインできます。
OpenSSH はクライアント/サーバー技術を使用します。 ssh プログラムを実行しているユーザーなどのクライアントは、ターゲット ホスト上の sshd サーバーへの接続を開始します。 SSH プロトコルのメッセージが交換されて、クライアントがターゲット ホストに対して認証され、リモート アクセスが許可または拒否されます。許可されている場合、TCP/IP 接続が構築され、クライアントはターゲット システム上の sshd デーモンによって生成されたアプリケーションとコマンドとデータを交換できます。
OpenSSH ツールの利点は、すべての通信交換が暗号化されることです。ユーザー名、パスワード、セッション データなどの認証情報は、暗号化されていない形式で送信されることはありません。これは、クリア テキスト転送のみを使用する telnet や ftp などの代替手段とは異なります。
openssh サーバー RPM パッケージは /usr/sbin/sshd を提供します デーモンとその構成ファイル
SSH 通信プロトコルには、バージョン 1 とバージョン 2 の 2 つのバージョンがあります。scp などのクライアントと sshd サーバーの両方が同じプロトコル バージョンを使用する必要があります。 sshd サーバーはデフォルトで両方のプロトコル バージョンをサポートしますが、各バージョンは個別に設定されます。
クライアントと sshd デーモン間の接続は、UDP または TCP プロトコルのいずれかを使用して、デフォルトで TCP/IP ポート 22 で行われます。まず、クライアントとサーバーは暗号化方式に同意する必要があります。sshd はサポートされている暗号のリストを送信し、クライアントはその優先順位を選択します。サーバーは /etc/ssh/ssh_host_key のいずれかを使用してホストを識別します (プロトコル バージョン 1) または /etc/ssh/ssh_host_[rd]sa_key のいずれか (プロトコル バージョン 2)。これにより、クライアントは IP スプーフィングや中間者攻撃を検出できます。ホスト ID が検証されると、クライアントは 1 つ以上の認証方法を試行して、ユーザーのシステム アクセス資格情報を確立します。公開暗号化キーが最初に試行され、従来のパスワード チャレンジにフォールバックされます。 ssh クライアントを使用して、次のように「-v」スイッチを追加すると、完全なネゴシエーションを表示できます。
$ ssh -vvv myhost.example.com
sshd デーモンは /etc/pam.d/sshd を使用します ファイルを参照して、そのホストに必要な認証規則を決定します。デフォルト ファイルは openssh-server RPM パッケージによって提供され、ほとんどのサイトに適しています。
ユーザーアクセスが認証された後、sshd(8) デーモンは、TCP/IP セッションに添付された標準入力/エラー/出力ファイル (stdin、stderr、stdout) を使用して、クライアントの目的のアプリケーション プログラムを開始します。
sshd(8) デーモンで利用可能な機能と動作は、システム全体の構成 /etc/ssh/sshd_config ファイルによって制御されます。デフォルト ファイルは RPM パッケージで提供されますが、ローカルの要件に合わせて編集できます。たとえば、ssh を使用した root ログインを防止するには、sshd_config 設定を次のスニペットのように変更できます:
# vi /etc/ssh/sshd_config PermitRootLogin no
サービス コントロール
sshd サービスをオンデマンドで管理するには、service コマンドを使用するか、/etc/init.d/sshd スクリプトを直接実行します。
# /sbin/service sshd help Usage: /etc/init.d/sshd {start|stop|restart|reload|condrestart|status}
# /etc/init.d/sshd help Usage: /etc/init.d/sshd {start|stop|restart|reload|condrestart|status}
利用可能なコマンドは次のとおりです:
コマンド | 説明 |
---|---|
開始 | sshd デーモンを起動します。 |
停止 | sshd デーモンを停止します。 |
再起動 | 停止してから開始するコマンド シーケンスに相当します。 |
リロード | サービスを中断することなく、sshd デーモンに構成ファイルの再読み込みを強制します。 |
condrestart | sshdデーモンが現在実行中の場合、これは再起動コマンドと同じです。デーモンが実行されていない場合、アクションは実行されません。 RPM パッケージのインストールで、まだ実行されていないサービスの開始を避けるためによく使用されます。 |
ステータス | sshd デーモンが実行されている場合は、その PID (プロセス ID) を報告します。実行されていない場合は、それも報告してください。 |
sshd デーモンは、最も一般的には sshd サービスまたは xinetd(8) デーモンによって開始されます。コマンドライン引数を直接指定することは可能ですが、通常は行われません。代わりに、/etc/sysconfig/sshd ファイルを作成して ${OPTIONS} 変数を定義することにより、追加のコマンドライン引数を sshd(8) デーモンに提供できます。
# Additional command line options for sshd OPTIONS="-q"
この例では、quiet モードをオンにして、sshd が各セッションの開始、認証、および終了をログに記録しないようにします。利用可能なコマンド ライン オプションの詳細については、sshd のオンライン マニュアル ページを参照してください。
構成
起動時に sshd サービスを管理するには、chkconfig ツールを使用します:
# /sbin/chkconfig --list sshd sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# /sbin/chkconfig sshd on
# /sbin/chkconfig --list sshd sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
サイト依存の操作用に sshd デーモンを調整するために、さまざまな構成ファイルが使用されます。これらについて以下に説明します:
構成ファイルのパス | 説明 |
---|---|
/etc/ssh/sshd_config | 必要な構成ファイル。ほとんどのデフォルト値はコメントとして提供されます。 |
/etc/ssh/ssh_host_key | SSH プロトコル バージョン 1 に使用されるホスト キーが含まれています。プロトコル バージョン 1 が使用されている場合にのみ必要です。 |
/etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key | SSH プロトコル バージョン 2 に使用されるホスト キーが含まれています。プロトコル バージョン 2 が使用されている場合にのみ必要です。 |
/etc/motd | ログイン成功時に ssh クライアントに表示される今日のファイルのメッセージ |
~/.hushlogin | ファイルが存在する場合、ログインに成功しても /etc/motd ファイルは ssh によって表示されません。 |
/etc/nologin | ファイルが存在する場合、その内容がクライアントによって表示され、セッションが終了します。 root ログインでは無視されます。 |
~/.ssh/environment | ファイルが存在し、sshd_config パラメータ PermitUserEnvironment が設定されている場合、このファイルのシェル環境変数が SSH セッションにエクスポートされます。 |
~/.ssh/rc /etc/ssh/sshrc | ファイルは示されている順序でチェックされ、最初に見つかったファイルが実行されます。どちらも見つからない場合、xauth ユーティリティが実行されます。 |
~/.ssh/authorized_keys | RSA セッション認証に使用される公開鍵を一覧表示します。 |
~/.ssh/known_hosts /etc/ssh/ssh_known_hosts | すべての既知のホストのホスト公開鍵を含みます。ユーザーごとのファイルは自動的に維持されます。オプションのグローバル ファイルは、システム管理者によって維持されます。 |
/etc/モジュリ /etc/ssh/モジュール | man ページとは異なり、この実装ではファイル /etc/moduli は使用されません。 /etc/ssh/moduli ファイルには、「Diffie-Hellman Group Exchange」プロトコル ネゴシエーションに使用される Diffie-Hellman グループが含まれています。 |
/var/empty/sshd | 認証フェーズが完了する前に権限を分離する際に使用される chroot ディレクトリ。 root が所有し、誰でも書き込み可能ではないこのディレクトリには、通常、時刻と日付を表示するための etc/localtime ファイルのみが含まれます。 |
/etc/hosts.allow /etc/hosts.deny | tcp_wrappers 機能によって適用されるアクセス制御。詳細については、tcpd を参照してください。 |
~/.rhosts | RSA 認証またはホストベースの認証に使用されます。パスワード交換を必要としないログインを識別するためのユーザー名/ホスト名のペアのリスト。 |
~/.shosts | ~/.rhosts に似ていますが、rlogin または rshd ユーティリティでは無視されます。 |
/etc/hosts.equiv | クライアント ホストとサーバー ホストの両方でユーザー名が一致する限り、パスワードの確認が必要ないホストのリスト。行にユーザー名も含まれている場合、クライアント マシン上のそのユーザーは、ホストのルート アカウントであっても、任意のサーバー アカウントにログインできます。これは一般的に推奨されません。 |
/etc/shosts.equiv | /etc/hosts.equiv ファイルと同様に処理され、このファイルは rsh および rshd デーモンによって無視されます。 |
構成ファイル /etc/ssh/sshd_config
以下はサンプル構成ファイル /etc/ssh/sshd_config です。
# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/local/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value. # If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER # #Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key # Ciphers and keying #RekeyLimit default none # Logging #SyslogFacility AUTH SyslogFacility AUTHPRIV #LogLevel INFO # Authentication: #LoginGraceTime 2m #PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no PasswordAuthentication no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no #KerberosUseKuserok yes # GSSAPI options GSSAPIAuthentication yes GSSAPICleanupCredentials no #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no #GSSAPIEnablek5users no # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several # problems. UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #UsePrivilegeSeparation sandbox #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS yes #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # Accept locale-related environment variables AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS # override default of no subsystems Subsystem sftp /usr/libexec/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server