ローカル開発環境で書いたコードをVPSにアップしようとしたとき、私は気づいてしまった。
「あれ・・・scpコマンドってどうやって打ったっけ・・・?」
そこでメモを残すことに。
scpの基本 ファイルをリモートサーバに転送する
scpコマンドの使い方は以下の通り
$ scp file.txt host-user@example.targethost.com:/home/host-user/.
↑のコマンド例では”file.txt”というテキストファイルを、
userというユーザー名(example.targethost.com内のユーザー”host-user”)で、
対象ホスト or サーバ(example.targethost.com)の内部の
/home/host-user/というディレクトリに同名(/home/host-user/file.txt)で転送する
という意味になる。
この際、sshができるようになっていなければならない。また、サーバ側のディレクトリの権限等で転送できる場所も変わるので注意。
また、ディレクトリごと送る時は-rオプションをつける必要がある。
例:MacBookから”node/”ディレクトリをexample.targethost.comというサーバに転送する
[local-user@MacBookPro]$ scp -r node/ host-user@example.targethost.com:/home/host-user/.
# 秘密鍵認証の設定をしていないとパスワード認証になる
host-user@example.targethost.com's password:
index.ejs 100% 596 0.6KB/s 00:00
index.js 100% 2639 2.6KB/s 00:00
server.js 100% 254 0.3KB/s 00:00
style.css 100% 252 0.3KB/s 00:00
[local-user@MacBookPro]$
local-userという名前でログインしている自分のMacBookProから、
exapmle.targethost.comの/home/host-user/配下にnode/ディレクトリを送る
この時host-userはexample.targethots.comで準備されたものとする。
ディレクトリごと送る時は-rオプションをつけることを忘れてはいけない。
参考資料
scpコマンドでサーバー上のファイルorディレクトリをローカルに落としてくる