ssh

ネットワーク

書き方

ssh [-p <port>] <user>@<host> [command]

別の機械に暗号化された shell を開きます。秘密鍵が他人にも読める許可なら ssh は端から拒むので `chmod 600` が必要で、ポートはここでは `-p` ですが scp と sftp では `-P` です。

よく使うオプション

オプション意味
-p 2222Port. Note that scp and sftp spell the same thing -P.
-i ~/.ssh/id_ed25519Use a specific private key.
-L 8080:localhost:80Local forward: your port 8080 reaches the remote side.
-R 9000:localhost:3000Remote forward: their port 9000 reaches your machine.
-D 1080A local SOCKS proxy tunnelled through the host.
-J <bastion>Jump through a bastion host in one command.
-N -fNo remote command, go to the background. The pair used for tunnels.
-v / -vvvShow 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.com

Log in on a non-standard port.

ssh -N -L 5432:localhost:5432 deploy@db.example.com

Reach the remote database as if it were local.

ssh -vvv git@github.com

See 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