Ssh

當 SSH 授權密鑰被限制為命令時,命令如何讀取呼叫中的參數?

  • November 5, 2021

假設授權密鑰僅限於測試參數的命令,例如command="bin/testparameters",ssh 呼叫是:

ssh user@host 'some parameters which may include other commands'

怎麼能bin/testparameters讀到值'some parameters which may include other commands'

傳遞的附加參數ssh出現在環境變數中SSH_ORIGINAL_COMMAND

$ tail -1 .ssh/authorized_keys
command="printf '%s\n' \"$SSH_ORIGINAL_COMMAND\"" ssh-rsa AAAA....kz6C5 user@example.com
$ ssh user@example.com foo bar farkle
foo bar farkle

引用自:https://unix.stackexchange.com/questions/676246