ssh
ネットワーク
書き方
ssh [-p <port>] <user>@<host> [command]別の機械に暗号化された shell を開きます。秘密鍵が他人にも読める許可なら ssh は端から拒むので `chmod 600` が必要で、ポートはここでは `-p` ですが scp と sftp では `-P` です。
よく使うオプション
| オプション | 意味 |
|---|---|
| -p 2222 | Port. Note that scp and sftp spell the same thing -P. |
| -i ~/.ssh/id_ed25519 | Use a specific private key. |
| -L 8080:localhost:80 | Local forward: your port 8080 reaches the remote side. |
| -R 9000:localhost:3000 | Remote forward: their port 9000 reaches your machine. |
| -D 1080 | A local SOCKS proxy tunnelled through the host. |
| -J <bastion> | Jump through a bastion host in one command. |
| -N -f | No remote command, go to the background. The pair used for tunnels. |
| -v / -vvv | Show the handshake, which is how you find out why a key was refused. |
| -o <Option>=<value> | Any ssh_config setting for this one connection. |
例
ssh -p 2222 deploy@example.comLog in on a non-standard port.
ssh -N -L 5432:localhost:5432 deploy@db.example.comReach the remote database as if it were local.
ssh -vvv git@github.comSee exactly which keys were offered and rejected.
つながらないとき、どこまで行けたのかを絞ります — 名前が引けないのか、経路がないのか、ポートが閉じているのか。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. ssh は何をしますか。
別の機械に暗号化された shell を開きます。秘密鍵が他人にも読める許可なら ssh は端から拒むので `chmod 600` が必要で、ポートはここでは `-p` ですが scp と sftp では `-P` です。
Q. どう打ちますか。
ssh [-p <port>] <user>@<host> [command] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは9個です。全部は man ssh にあります。このコマンドはネットワークの仲間です。
関連するコマンド
man ページ: man ssh