LoginSignup
24
24

More than 5 years have passed since last update.

scpコマンドでリモートサーバとローカルでファイルのやり取りをする

Last updated at Posted at 2014-06-11

この辺りを参照してみてください。

基本的なルールとしては

$ scp [転送元] [転送先]

また、リモートの場合は

$ scp サーバアカウント情報:/ディレクトリ名/ファイル名

というルールを覚えておけばOK。
サーバアカウント情報は、基本的には

scp -P ポート番号 -i 鍵ファイル ユーザ名@IPアドレスorサーバ名

という形で入力します。オプションは以下です。

$ scp
usage: scp [-12346BCEpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2

もし、簡単sshログイン設定がされていれば、設定されたHost名だけでオッケー。

例としては、


①リモートサーバ(config設定あり)→ローカルホスト
$ scp test:/var/www/index.php /Applications/MAMP/htdocs/


②ローカルホスト→リモートサーバ(config設定あり)
$ scp /Applications/MAMP/htdocs/index.php test:/var/www/


③リモートサーバ→リモートサーバ(config設定あり)
$ scp test:/var/www/index.php test2:/var/www/


④リモートサーバ(config設定なし)→ローカルホスト
$ scp -P 00000 -i ~/.ssh/id_rsa admin@000.000.00.000:index.php /Applications/MAMP/htdocs/

といった具合です。

24
24
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
24
24