2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Linux】scpコマンドでファイルをコピーする

Last updated at Posted at 2025-04-11

はじめに

ローカルとリモートサーバ間でファイルをやり取りしたいときに便利なscpコマンド
SSH(Secure Shell)を使ってファイルを暗号化しながら安全に転送できたので、備忘録として残します。

内容

  • scpコマンドは、SSHを利用してリモートとローカル間でファイルをコピーするためのコマンド
scp [オプション] [コピー元] [コピー先]

リモート → ローカルにファイルをコピー

  • ファイル指定する場合
scp user@remote_host:/path/to/file.csv ./local_path
  • 複数ファイルを一度に持ってきたい場合
scp cuser@remote_host:/path/to/*.csv ./local_path
  • 上記の形式だとzsh*(アスタリスク)がファイルにマッチしないとき、ローカル側のパスとして展開しようとしてエラーになるので注意
zsh: no matches found: cuser@remote_host:/path/to/*.csv
  • クオートで囲む
scp "cuser@remote_host:/path/to/*.csv" ./local_path

ローカル → リモートにファイルをコピー

scp ./local_path/file.csv user@remote_host:/remote/path/

まとめ

サーバー上のファイルコピーしたいときに便利なコマンドだったので、備忘録としてまとめ。
必要に応じて -r オプション(ディレクトリ丸ごとコピー)や -P オプション(ポート指定)もできるので便利なコマンド。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?