简体   繁体   English

通过ssh键将标志传递到bash脚本

[英]passing flags to bash script via ssh key

So lets say I have ClientA and ServerB set up and I have ServerB set up to run a backup script. 因此,可以说我设置了ClientA和ServerB,并且设置了ServerB以运行备份脚本。 Now for reasons which are irrelevant to the issue at hand, the backup script needs to run several bash scripts on ClientA. 现在,由于与当前问题无关的原因,备份脚本需要在ClientA上运行多个bash脚本。 Now for security reasons, I have a "backup" user set up on ClientA and a key pair allowing ServerB to log into ClientA as this "backup" user. 现在出于安全原因,我在ClientA上设置了一个“备份”用户,并使用一个密钥对允许ServerB以该“备份”用户身份登录到ClientA。 However I would like to take this a step further and only allow the key to work on a single script. 但是,我想更进一步,只允许键在单个脚本上工作。

Here is that key: 这是关键:

command="/backup.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa A......

My problem is that I run the script on ClientA several times and each time I use a number of different flags. 我的问题是,我多次在ClientA上运行脚本,并且每次使用许多不同的标志。 However, I can not seem to pass these flags through the SSH key. 但是,我似乎无法通过SSH密钥传递这些标志。

So lets say I try and run the following: 所以可以说我尝试运行以下命令:

$ ssh backup@ClientA "/backup.sh -b"

This will not pass the -b flag through because of the key I have set up on ClientA. 由于我在ClientA上设置的密钥,因此不会通过-b标志。 Is there a way to allow the flag to be passed through the ssh key I have set up? 有没有办法允许该标志通过我设置的ssh密钥传递?

Thanks. 谢谢。

You can use the environment variable SSH_ORIGINAL_COMMAND for this sort of thing. 您可以将环境变量SSH_ORIGINAL_COMMAND用于此类操作。

SSH_ORIGINAL_COMMAND This variable contains the original command line if a forced command is executed. SSH_ORIGINAL_COMMAND如果执行了强制命令,则此变量包含原始命令行。 It can be used to extract the original arguments 它可以用来提取原始参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM