LoginSignup
1
0

More than 3 years have passed since last update.

ssh の許可されない接続先でファイルリストを見る

Posted at

株式会社オズビジョンのユッコ (@terra_yucco) です。
今日も個人的な「ぷちっとしたメモ」になります。

ssh の許可されない接続先

「ハピタス」の連携相手でも、普段 scp で連携しているので ssh を許可していない相手がいます。

scp sftp

この 2 つしか許可されていないようです。

$ ssh -i /path/to/.ssh/user.pem -p 2222 user@hoge.example.com "ls -l /tmp"
Last login: Thu Jun 20 17:56:53 2019 from ec2-xx-xx-xxx-xxx.ap-northeast-1.compute.amazonaws.com

This account is restricted by rssh.
Allowed commands: scp sftp

If you believe this is in error, please contact your system administrator.

Connection to hoge.example.com closed.

ファイルリストが見たい

実は先日、サーバリプレイスによるトラブルが発生し、その復旧のため、先方に転送済みのファイルを見たい、という状況になりました。
普段だったら ssh で ls -l /path/to/files などするのですが、ssh が許可されていない場合どうするのか。

scp はどうか?

ssh と同じプロトコルだし、WinSCP を使うとファイルリストが取得できるので、scp コマンドでもコピーではなくてコマンド発行をする方法があるのか?と思ってずっと調べていました。
ただ、どうもうまい方法は見つからず。
よくよく見たら、WinSCP も scp コマンドで表示しているわけではなかったようです。

正解は sftp

WinSCP もプロトコルは sftp でした。

image.png

ということで、sftp コマンドでファイルリストを取ってみます。
ssh オプションの指定方法が独特すぎる…。

$ sftp -oIdentityFile=/path/to/.ssh/user.pem -oPort=2222 user@hoge.example.com
Connecting to hoge.example.com...
sftp> ls -l /tmp
-rw-r--r--    1 480      500         12977 Aug  8  2016 user-20160808.txt.gz
-rw-r--r--    1 480      500            59 Aug  8  2016 user-20160808.txt.ok.gz
sftp> exit
$

(∩´∀`)∩

1
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
1
0