scp
ネットワーク
書き方
scp [-P <port>] <src> <user>@<host>:<dest>ssh に乗せてファイルを一度で複写します。ポートは大文字の `-P`、遠隔側の道にはコロンが必要で、大きい転送や繰り返す転送なら、変わっていないものを飛ばして再開できる rsync のほうが向きます。
よく使うオプション
| オプション | 意味 |
|---|---|
| -P 2222 | Port, capital P. Lowercase -p means "preserve timestamps" here. |
| -r | Copy a directory and everything under it. |
| -i <key> | Use a specific private key. |
| -C | Compress in transit. |
| -3 | Copy between two remote hosts by routing through your machine. |
| -O | Use the old SCP protocol; OpenSSH 9 and later default to SFTP. |
例
scp -P 2222 build.tar.gz deploy@example.com:/tmp/Upload one file. The remote side needs the colon.
scp -r deploy@example.com:/var/log ./logsDownload a whole directory.
つながらないとき、どこまで行けたのかを絞ります — 名前が引けないのか、経路がないのか、ポートが閉じているのか。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. scp は何をしますか。
ssh に乗せてファイルを一度で複写します。ポートは大文字の `-P`、遠隔側の道にはコロンが必要で、大きい転送や繰り返す転送なら、変わっていないものを飛ばして再開できる rsync のほうが向きます。
Q. どう打ちますか。
scp [-P <port>] <src> <user>@<host>:<dest> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man scp にあります。このコマンドはネットワークの仲間です。
関連するコマンド
man ページ: man scp