# SSHの設定

## 概要 <a href="#overview" id="overview"></a>

(サーバー設定と環境設定についてはユーザーが行います。)

Secure Shell (SSH) を使用すると、コンピュータへの安全な認証付きのリモートアクセスが可能になります。SSHトラフィックは完全に暗号化されており、デフォルトではポート22で実行されます。テスティング目的で対象オペレーティングシステムでSSHを有効にする手順については、以下をご参照ください。

## Linux

Linux では、SSH 接続を受け入れるためにSSHデーモンが実行されている必要があります。ほとんどのLinuxディストリビューションにはOpenSSHサーバーがインストールされていますが、サービスが有効になっていない場合があります。サービスを有効にし、再起動時に開始するサービスのリストに追加する必要があります。

以下のコマンドを実行して、LinuxシステムでSSHが実行されていることを確認します。

```sh
ps aux | grep sshd
```

SSHが実行されていない場合、OpenSSHをインストールするかSSHを有効にする必要があります。以下のコマンドはUbuntuでの例です。

```bash
apt-get install openssh-server
systemctl enable ssh
systemctl start ssh
```

備考:

* ssh をインストールして有効にするには、Sudo権限が必要な場合があります。
* インストールコマンドは、Linuxディストリビューションによって異なる場合があります。

## Windows

通常、WindowsにはSSHがインストールされていませが、Microsoftが管理するWindows機能パッケージを介して簡単にインストールできます。以下のPowerShellスクリプトで、1) SSH をインストールし、2) SSH サービスを開始して再起動のたびに開始するようにし、3) ファイアウォールがSSH接続を許可するようにします。

```powershell
# Install OpenSSH
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

# Start service and make sure it automatically starts after reboot.
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

# Make sure the the firewall will allow SSH connections
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
    Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
    Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
```

### Windows Shell <a href="#shell" id="shell"></a>

Windows SSHはデフォルトでPowerShellかCMDのどちらかに設定できます。Keeper RotationではPowerShellコマンドを使用します。デフォルトのシェルがCMDの場合、Keeper Rotationは `PowerShell Invoke-Command -ScriptBlock { COMMANDS }`を介してローテーションコマンドを呼び出します。デフォルトのシェルをPowerShellに変更するには、以下のPowerShellコマンドを呼び出します。

```powershell
# Enable PowerShell in SSH
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell `
  -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" `
  -PropertyType String -Force
```

## MacOS

MacOSにはSSHがインストールされていますが、通常は有効になっていません。

UIで有効にするには、**\[一般]**&#x3092;クリックしてから右側&#x3067;**\[共有]**&#x3092;クリックし、**「リモートログイン」** をONにします。

<figure><img src="/files/mTJbhHCl7NwIh4oKuVkg" alt="" width="544"><figcaption></figcaption></figure>

コマンドラインで有効にするには、以下のコマンドを呼び出します。

```bash
$ sudo systemsetup -setremotelogin on
```

備考:

* このコマンドラインを使用した方法では、フルディスクアクセスの権限が必要です。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/privileged-access-manager/references/setting-up-ssh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
