LoginSignup
47
43

More than 5 years have passed since last update.

Macbookでsftpコマンド実行

Last updated at Posted at 2014-09-06

Macbookからsftpを実行しようとしたら若干引っかかったので覚え書きです。

usage

$ sftp
usage: sftp [-1246Cpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
[-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
[-o ssh_option] [-P port] [-R num_requests] [-S program]
[-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host

実行例

ログイン

$ sftp -P [※ポート番号] [ユーザ名]@[接続対象のIPアドレス]
user@xx.xx.xx.xx's password:
Connected to xx.xx.xx.xx.
sftp>
※port番号はssh接続ポート、変更してなければ指定する必要なし
その場合は、
$ sftp [ユーザ名]@[接続対象のIPアドレス]

ファイルをmacbookからput

sftp> put ./test.txt
Uploading ./test.txt to /home/user/test.txt
./test.txt 100% 415 0.4KB/s 00:00

dirでputされたことを確認
sftp> dir
test.txt

カレントディレクトリの確認もできる

sftp> pwd
Remote working directory: /home/user

macbookへget

sftp> get test.txt
Fetching /home/user/test.txt to test.txt
sftp>

!lsでmacbookでgetされていることを確認
sftp> !ls
test.txt
sftp> bye

引っかかったところ

ポートの指定は後ろに書いちゃダメ、それだけ。
usageちゃんと見ろという感じです。。

$ sftp [ユーザ名]@[接続対象のIPアドレス] -P [ポート番号]
usage: sftp [-1246Cpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
[-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
[-o ssh_option] [-P port] [-R num_requests] [-S program]
[-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host

おまけ

接続先(linux)でsftpの許可設定について

sshd_configファイルを編集する

# vi /etc/ssh/sshd_config

/etc/ssh/sshd_config
# override default of no subsystems
# Subsystem       sftp    /usr/libexec/openssh/sftp-server

Subsystem sftp... の行のコメントインを行う

/etc/ssh/sshd_config
# override default of no subsystems
 Subsystem       sftp    /usr/libexec/openssh/sftp-server

sshd再起動

sshd再起動にて反映
# /etc/init.d/sshd restart

47
43
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
47
43