シェル用のSSH ForceCommandを使用すると、定期的なログインとリモートコマンドの実行を同時に維持できます。

シェル用のSSH ForceCommandを使用すると、定期的なログインとリモートコマンドの実行を同時に維持できます。

このコマンドを実行/調整し、ForceCommandを使用してこのユーザーにシェルを提供するにはどうすればよいですか?

クライアントコマンド

(cat ./sudoPassword ./someCommandInput) | ssh user@ip "sudo -Sp '' someCommand"

サーバー sshd_config

ForceCommand /bin/bash

背後の制限は、ForceCommandがそのユーザーにシェルを提供するメカニズムでなければならず、上記の一般的なコマンドssh user@ipも機能するはずです。

私は次のようなさまざまな構成を試しました。

ForceCommand /bin/bash -ic $SSH_ORIGINAL_COMMAND ls
ForceCommand /bin/bash -s < $SSH_ORIGINAL_COMMAND
ForceCommand /bin/bash -c $SSH_ORIGINAL_COMMAND

また、-ttなどのsshオプションを提供してクライアントコマンドを試してみましたが、正しい設定が見つからないようです。

ベストアンサー1

ラッパースクリプトをForceCommand次の.scriptとして使用します(例:に保存/usr/local/bin/myshell)。

#! /bin/bash

if [[ -n $SSH_ORIGINAL_COMMAND ]] # command given, so run it
then
    exec /bin/bash -c "$SSH_ORIGINAL_COMMAND"
else # no command, so interactive login shell
    exec bash -il
fi

実行中:

% grep ForceCommand -B1 /etc/ssh/sshd_config
Match user muru
    ForceCommand /usr/local/bin/forceshell
% ssh muru@localhost
$ ls
Desktop   Documents   Downloads   Music   Pictures   Public   Templates   Videos
$ logout
Connection to localhost closed.
% ssh muru@localhost echo foo
foo
% ssh muru@localhost echo '*'
Desktop   Documents   Downloads   Music   Pictures   Public   Templates   Videos

おすすめ記事