Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

sshのauthorized_keysのcommandでパイプは使えるか

authorized_keyscommand=オプションにパイプを含むコマンドを指定できるか実験。

command="find /home/satob -maxdepth 1 -name '*.sh' | xargs grep '#!'" ssh-ed25519 AAAAC3Nz... pipe@example.com

実行してみたらこんな感じ。問題なく実行できた。結局、内部では/etc/passwdで指定されたシェルが動いているから、ログインシェルでできることはcommand=でも可能みたい。

$ ssh -i id_pipe satob@localhost
/home/satob/sanitize1.sh:#!/bin/bash
/home/satob/sanitize2.sh:#!/bin/bash
/home/satob/sanitize4.sh:#!/bin/bash
/home/satob/sanitize3.sh:#!/bin/bash
Connection to localhost closed.

$0も参照できた。

command="echo $0" ssh-ed25519 AAAAC3Nz... shtype@example.com
$ ssh -i id_shtype satob@localhost
bash
Connection to localhost closed.

シェルは/etc/passwdで指定したものが使われる、という話は以下を参照。/sbin/nologinを指定しているユーザでもsshでトンネリングはできるが、command=は使えないことになる。 unix.stackexchange.com