首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于shell的SSH ForceCommand,同时保持常规登录和远程命令执行的可能性

用于shell的SSH ForceCommand,同时保持常规登录和远程命令执行的可能性
EN

Unix & Linux用户
提问于 2019-06-25 15:09:02
回答 1查看 9.3K关注 0票数 2

我如何运行/调整这个命令,同时使用ForceCommand给这个用户提供他们的shell?

客户端命令

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

服务器sshd_config

ForceCommand /bin/bash

幕后的限制是,ForceCommand需要成为给这个用户提供一个shell的机制,除了上面的命令之外,一个典型的ssh user@ip也需要工作。

我尝试过各种配置,例如

代码语言:javascript
复制
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 ),但我似乎找不到正确的配置。

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2019-06-25 15:52:33

使用包装器脚本作为ForceCommand。类似于这样的脚本(比如,保存在/usr/local/bin/myshell上):

代码语言:javascript
复制
#! /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

在行动中:

代码语言:javascript
复制
% 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
票数 4
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/526848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档