PSFTPの利用
1 PSFTPとは?
PSFTPはSSHで使えるファイル転送(FTP)プログラムです。通常のFTPはログインする時にパスワードがそのままネットを流れ危険ですし、転送中のファイルもそのまま流れますので内容を読まれる可能性があります。これに対し現在のOpenSSHに含まれるsftpを利用することにより、ログインからファイル転送まですべてデータを暗号化した状態で行うことができます。WindowsのMS-DOSプロンプト上で動くこのsftpコマンドがPSFTPです。
2 sshdの設定
sftpを利用するにはサーバ側の設定がsftpの利用が可能になっている必要があります。OpenSSHのsshd用設定ファイル(sshd_config)は通常/etc/ssh/か/usr/local/etc/にありますので最後の1行が有効(頭に"#"が付いていない)にして下さい。設定後、再起動で変更が反映されます。
sftpを利用する
Uncomment if you want to enable sftp
Subsystem sftp /usr/libexec/sftp-server ←#がある場合は取る
3 PSFTPのインストール
PuTTYと同じPuTTY Download Pageよりダウンロードできます。
* PSFTP: psftp.exe
ダウンロードした"psftp.exe"はそのままダブルクリックで起動します。
4 サーバへのログイン
コマンドでopen ホスト名でログインが開始されます。
psftp: no hostname specified; use "open host.name" to connect
psftp> open 192.168.0.10 ←192.168.0.10を指定して開始
login as: test ←ユーザ名の指定
Using username "test".
vpn@vpn1.tempest.jp's password: ←パスワードの入力
Remote working directory is /home/test ←ログイン完了
psftp>
ログイン後は通常のFTPと同じようにコマンドを利用できます。
psftp> cd .ssh ←ディレクトリの移動
Remote directory is now /home/test/.ssh
psftp> ls ←ファイルの一覧
Listing directory /home/vpn/.ssh
drwx------ 4 test test 4096 Mar 19 13:06 .
drwx------ 8 test test 4096 Mar 19 13:05 ..
-rw------- 1 test test 899 Mar 19 13:05 authorized_keys2
-rw-r--r-- 1 test test 219 Mar 19 13:04 id_rsa.pub
5 ダウンロード
getコマンドでファイルのダウンロードができます。!に続けてコマンドを打つとローカル側(この場合はWindows)で実行されます。
psftp> get test.exe
remote:/home/vpn/.ssh/test.exe => local:test.exe
psftp> !dir ←Windowsの内容確認
ドライブ C: のボリュームラベルはありません.
ボリュームシリアル番号は 2683-18DC
ディレクトリは C:\tmp
. <DIR> 02-03-18 15:38 .
.. <DIR> 02-03-18 15:38 ..
TEST EXE 331,776 02-03-18 15:39 test.exe ←保存された
6 アップロード
putコマンドでファイルのアップロードができます。
psftp> put pscp.exe
ocal:pscp.exe => remote:/home/test/.ssh/pscp.exe
psftp> ls
-rw-r--r-- 1 test test 229376 Mar 22 15:10 pscp.exe ←保存された
7 利用できるコマンド
helpと打つとPSFTPで利用できるコマンドの一覧が表示されます。
psftp> help
! run a local Windows command
bye finish your SFTP session
cd change your remote working directory
chmod change file permissions and modes
del delete a file
dir list contents of a remote directory
exit finish your SFTP session
get download a file from the server to your local machine
help give help
lcd change local working directory
lpwd print local working directory
ls list contents of a remote directory
mkdir create a directory on the remote server
mv move or rename a file on the remote server
open connect to a host
put upload a file from your local machine to the server
pwd print your remote working directory
quit finish your SFTP session
reget continue downloading a file
ren move or rename a file on the remote server
reput continue uploading a file
rm delete a file
rmdir remove a directory on the remote server
8 終了
byeでPSFTPの接続が解除されます。
9 鍵を使って接続する。
PuTTYでホストや鍵がSessionに登録してあれば、そのSession名を指定することで鍵を使ったログインが可能になります。
psftp: no hostname specified; use "open host.name" to connect
psftp> open putty test
Using username "test".
Authenticating with public key "rsa-key-20020320"
Passphrase for key "rsa-key-20020320":
Remote working directory is /home/test
psftp>
2002-03-20 作成