Passing SSH Command Parameters


 
Thread Tools Search this Thread
Operating Systems Solaris Passing SSH Command Parameters
# 1  
Old 03-02-2007
Question Passing SSH Command Parameters

On Solaris 5.9, is there any way to pass parameter(s), via SSH, to a command defined in the remote host's authorized_keys file?

We have a menu that uses SSH to control some apps on our various hosts. I've been tasked with enhancing it and making it more secure.

So far, the local host menu will use SSH to call a .ksh script on the remote host, with one of 4 parameters, to either start, stop, restart or check a program's status. That works fine.

What we would like to do is this:

1. Put the remote .ksh script name in the authorized_keys file, on the remote host, in the front of the key line, for the user calling it, from the local host. That would limit the user, using the menu, to only being able to run this .ksh script.

2. When the user make a choice on the local host menu, pass only the chosen parameter via the SSH login.

When I try it, the remote .ksh script runs, but errors out due to the parameter passing failing.

Is there any way to pass just the parameter(s)?
# 2  
Old 03-05-2007
PabloCruise77, when connecting with ssh, if you run any commands like this:
Code:
ssh abc@systemxyz "ls -l"

and environment variable called SSH_ORIGINAL_COMMAND is set to whatever parameters you pass in to ssh.

This is an excerpt of an authorized_keys2 file for a user test:
Code:
command="/tmp/test.sh $SSH_ORIGINAL_COMMAND" ssh-dss AAAAB3NzaC1kc3MAAACBAOpMZlRTUFSmgTscvAmqsOwLel2GGHhwTzXvGou6Ta38ZyS32rr
4ITr3ypiIaIbKDPD2c7p5G8t45ctpLvqRCqTUejtPryXgPrKcJuUzS7LG3sbxdahCKMQk/SGgSEdHXd11dQI/O1LwW3FZ25yQsmR9jqNM+wb8b0dM4upbxMxxAAA
AFQCl1eK8NrdbUhStz8WDd1Jc5sF/PwAAAIEAmJlpIcMnHpwBRSKNUto6GfxbLS17l73SDHB8rAP+meYPYfWOaPAsmkQc4UUIdkQJfOzSStgXKsyDH7ybaOWeDcE
Ffw7kroJbu3wXAOl+JPon5C6aXkvGBR3Y7qsBEMXlW57kraot4Rya/RUblh5xjYbYEDcJsPafABUKpRjCbYsAAACBAN1gXh2OHEwOV7+KnHo5fubclort79wAldw
OZ2A+v86hRcEgGb3Bl1qZRVuKvfrgR/OPvxoAeKmMjgrCDld0MgkC3ZdWOhuZhuCzBZRkZTCKnQF4k54r6sc6pWxS/NBBsyvzPmntcakaOb9cLrLf1JnXk3k4xiO
8E037y+OJ3WAX samba@abcxyz

The /tmp/test.sh file is like this:
Code:
#!/usr/bin/ksh

echo "this is a test"
echo $SSH_ORIGINAL_COMMAND
echo $@

As user samba, if I run
Code:
ssh test@abcxyz "hello there"

, I get this:
Code:
$ ssh test@ssunsp3 "hello there"
this is a test
hello there
hello there

So you can just edit the authorized_keys2 file and send the contents of the $SSH_ORIGINAL_COMMAND variable as parameters to the script that you are running.
# 3  
Old 03-05-2007
Computer It worked - with modifications

Thanks blowtorch!

At least on our version of Solaris 5.9, SSH_ORIGINAL_COMMAND contained the command and the parameter. Using the cut command, I was able to get the parameter and get the programs to act how I wanted.

I'm on a 3-month contract and this might get me a full-time gig!

Thanks a million!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing command line parameters into script

Not a good post. (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

2. Shell Programming and Scripting

Passing password with SSH command

Hi Experts, I have specific requirement where I want to pass the password with the ssh username@hostname command . I dont want to use RSA public and private keys also. Because that will be on production server and no one wants to give access like that. Second thing it is production... (14 Replies)
Discussion started by: sharsour
14 Replies

3. Shell Programming and Scripting

Passing 2+ parameters to one command

I have a script that uses more than one parameter. It looks like this: for i in `cat /tmp/listofpolicies`; do for x in $(cat /tmp/lst |sed 's/^/\/usr\/openv\/netbackup\/db\/class\//g'); do /usr/openv/netbackup/bin/admincmd/bpplinclude $i -delete -f $x;done;done The problem is that the... (3 Replies)
Discussion started by: newbie2010
3 Replies

4. Shell Programming and Scripting

passing arguments in remote ssh command?

i have a bash script on serverA, when i run the script on the server, it runs fine. the way to run the script is like this ./script "option1" Now i am trying to call it from local laptop using ssh command, my command is as the following ssh serverA ~/script "option1" and i got error... (7 Replies)
Discussion started by: fedora
7 Replies

5. Shell Programming and Scripting

Passing parameters to Shell script for GREP command

I am using grep to capture date from a file . Since i need to use the shell script for different dates ,is it possible to pass the date parameter to the shell script the Script is as below grep -E "08 Aug 2008|2008-08-08"* somefile.txt>test.txt The above script file greps the... (1 Reply)
Discussion started by: sud.tech
1 Replies

6. Shell Programming and Scripting

Passing SSH Command Parameters

Hi, I wan to pass arguments to remote script in Unix . For that I'm using ssh PFB the code I'm using: ssh -t -l osdac 10.81.33.51 "cd /appl/OSD/LOGS/flstr010/test.sh "$1" "$2"" Problem is I'm not able to pass second argument . Can anyone plz help me in resolving this. (5 Replies)
Discussion started by: suchitasaner27
5 Replies

7. AIX

Passing a command over SSH

I'm trying to run a command over ssh to AIX 5.2, something like: ssh machine ls but it just hangs. I can ssh into the machine and run a command, but can't pass it like above. Is there a security setting that disables this by default? If so, how do I change it? Thanks! (8 Replies)
Discussion started by: hansnueski
8 Replies

8. Shell Programming and Scripting

passing more than 9 parameters

hi, i am passing around 14 parameters for a script a=$1 b=$2 c=$3 d=$4 e=$5 f=$6 g=$7 h=$8 i=\"${9}\" shift j=\"${1}\" still for j it is displaying the 1st parameter value..how to make it take the 10th parameter (2 Replies)
Discussion started by: dnat
2 Replies

9. Shell Programming and Scripting

passing command line parameters to functions - sh

All, I have a sh script of the following tune: function a () { #functionality.. } function b () { #functionnlity.. } function check () { # this function checks for env and if all fine call build } function usage () { #sh usage details } function build () { #calls either a or b or... (5 Replies)
Discussion started by: vino
5 Replies

10. UNIX for Dummies Questions & Answers

passing parameters to sleep command

Hi, Can any one help me with an example how to use Sleep command with parameters thanx, (1 Reply)
Discussion started by: nagaraju_svs
1 Replies
Login or Register to Ask a Question