쉘용 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

관련 정보