Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to a SSH command?

I configure a ssh command key like (in a remote mashine M1):

command="/usr/bin/nslookup",no-port-forwarding,no-X11-forwarding,no-agent-forwarding ssh-dss DEADBEEFDEADBEEF= [email protected]

To allow to run nslookup in M1 from a client machine C1. It works and i can run:

C1> ssh -i mylookup_key M1

And i get the nslookup execution on M1, but i need to pass parameters to get real work. How can i pass parameters to ssh command key?

p.d: I'm using nslookup as an example of the real program that I want to exec.

like image 324
Zhen Avatar asked Oct 28 '25 04:10

Zhen


2 Answers

Take a look at the $SSH_ORIGINAL_COMMAND variable which should contain the command passed to ssh. For example:

command="/usr/bin/nslookup $SSH_ORIGINAL_COMMAND",no-port-forwarding,no-X11-forwarding,no-agent-forwarding ssh-dss DEADBEEFDEADBEEF= [email protected]

Then try:

$ ssh -i mylookup_key M1 stackoverflow.com
like image 123
dogbane Avatar answered Oct 30 '25 18:10

dogbane


If I understand correctly you just want to run a command on the remote machine. The simple case is to just pass the command as the last parameter to ssh

ssh -i mylookup_key M1 nslookup stackoverflow.com

But you may need to be careful about quoting and special characters. e.g.

ssh -i mylookup_key M1 ./args.sh "1 2 3"
PROG:./args.sh
ARG[1]: 1
ARG[2]: 2
ARG[3]: 3
ssh -i mylookup_key M1 ./args.sh '"1 2 3"'
PROG:./args.sh
ARG[1]: 1 2 3
like image 42
Sodved Avatar answered Oct 30 '25 19:10

Sodved