我如何运行/调整这个命令,同时使用ForceCommand给这个用户提供他们的shell?
客户端命令
(cat ./sudoPassword ./someCommandInput) | ssh user@ip "sudo -Sp '' someCommand"
服务器sshd_config
ForceCommand /bin/bash
幕后的限制是,ForceCommand需要成为给这个用户提供一个shell的机制,除了上面的命令之外,一个典型的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我也尝试过使用client命令,给出了ssh选项(如-tt ),但我似乎找不到正确的配置。
发布于 2019-06-25 15:52:33
使用包装器脚本作为ForceCommand。类似于这样的脚本(比如,保存在/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 Videoshttps://unix.stackexchange.com/questions/526848
复制相似问题