public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] [OT] Passing env variable to ssh?
@ 2006-03-13 20:14 Jorge Almeida
  2006-03-13 20:36 ` Hans-Werner Hilse
  2006-03-13 21:16 ` Mariusz Pękala
  0 siblings, 2 replies; 5+ messages in thread
From: Jorge Almeida @ 2006-03-13 20:14 UTC (permalink / raw
  To: gentoo-user

Anyone knows a way to pass an environment variable to a openssh command?
I doubt there is a way, but who knows...
I want something like this:
myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand $myvar
This would execute a command with argument "whatever". The problem is that I
want to authenticate via a cryptographic key allowing only this command,
i.e., the file ~/.ssh/authorized_keys of myuser at remotebox has a line
command="~/bin/mycommand $myvar" <public-key>
This does not work, because remotebox doesn't know about $myvar. Of
course, if I could pass a variable to remotebox, the line might be just
command="~/bin/mycommand" <public-key>
and the ssh command would be
myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand
(the program itself would use the value of $myvar)

Any idea?

-- 
Jorge Almeida
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] [OT] Passing env variable to ssh?
  2006-03-13 20:14 [gentoo-user] [OT] Passing env variable to ssh? Jorge Almeida
@ 2006-03-13 20:36 ` Hans-Werner Hilse
  2006-03-13 22:42   ` Jorge Almeida
  2006-03-13 21:16 ` Mariusz Pękala
  1 sibling, 1 reply; 5+ messages in thread
From: Hans-Werner Hilse @ 2006-03-13 20:36 UTC (permalink / raw
  To: gentoo-user

Hi,

On Mon, 13 Mar 2006 20:14:33 +0000 (WET)
Jorge Almeida <jalmeida@math.ist.utl.pt> wrote:

> I want something like this:
> myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand $myvar
> [...]
> This does not work, because remotebox doesn't know about $myvar. Of
> course, if I could pass a variable to remotebox, the line might be just
> command="~/bin/mycommand" <public-key>
> and the ssh command would be
> myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand
> (the program itself would use the value of $myvar)

Hm, I think you're making it unnecessary complex. What's wrong with
just piping it on stdin? I.e.:

local$ echo "whatever" | ssh user@remote ./bin/mycommand
and in ./bin/mycommand:
---
#!/bin/sh
read myvar
# do whatever
---

Or do you in fact use a pseudo tty on remote side for interactive mode
(which would make this a little more difficult)?

If you want to keep your way of doing it, I just have a few hints, but
didn't test anything, just looked them up out of curiosity:
- read "man sshd_config", item AcceptEnv, PermitUserEnvironment
- read "man sshd", section LOGIN PROCESS

-hwh
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] [OT] Passing env variable to ssh?
  2006-03-13 20:14 [gentoo-user] [OT] Passing env variable to ssh? Jorge Almeida
  2006-03-13 20:36 ` Hans-Werner Hilse
@ 2006-03-13 21:16 ` Mariusz Pękala
  2006-03-13 22:44   ` Jorge Almeida
  1 sibling, 1 reply; 5+ messages in thread
From: Mariusz Pękala @ 2006-03-13 21:16 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1087 bytes --]

On 2006-03-13 20:14:33 +0000 (Mon, Mar), Jorge Almeida wrote:
> Anyone knows a way to pass an environment variable to a openssh command?
> I doubt there is a way, but who knows...
> I want something like this:
> myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand $myvar
> This would execute a command with argument "whatever". The problem is that I
> want to authenticate via a cryptographic key allowing only this command,
> i.e., the file ~/.ssh/authorized_keys of myuser at remotebox has a line
> command="~/bin/mycommand $myvar" <public-key>
> This does not work, because remotebox doesn't know about $myvar. Of
> course, if I could pass a variable to remotebox, the line might be just
> command="~/bin/mycommand" <public-key>
> and the ssh command would be
> myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand
> (the program itself would use the value of $myvar)
> 
> Any idea?

Stdin?

echo "$myvar" | ssh  myuser@remotebox.org ./bin/mycommand

?

-- 
No virus found in this outgoing message.
Checked by "grep -i virus $MESSAGE"
Trust me.

[-- Attachment #2: Type: application/pgp-signature, Size: 191 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] [OT] Passing env variable to ssh?
  2006-03-13 20:36 ` Hans-Werner Hilse
@ 2006-03-13 22:42   ` Jorge Almeida
  0 siblings, 0 replies; 5+ messages in thread
From: Jorge Almeida @ 2006-03-13 22:42 UTC (permalink / raw
  To: gentoo-user

On Mon, 13 Mar 2006, Hans-Werner Hilse wrote:

> Hi,
>
> On Mon, 13 Mar 2006 20:14:33 +0000 (WET)
> Jorge Almeida <jalmeida@math.ist.utl.pt> wrote:
>
>> I want something like this:
>> myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand $myvar
>> [...]
>> This does not work, because remotebox doesn't know about $myvar. Of
>> course, if I could pass a variable to remotebox, the line might be just
>> command="~/bin/mycommand" <public-key>
>> and the ssh command would be
>> myvar="whatever" ssh myuser@remotebox.org ./bin/mycommand
>> (the program itself would use the value of $myvar)
>
> Hm, I think you're making it unnecessary complex. What's wrong with
> just piping it on stdin? I.e.:
Indeed. The problem was me not understanding the relation of stdin with
ssh when in non interactive mode...
>
> local$ echo "whatever" | ssh user@remote ./bin/mycommand
> and in ./bin/mycommand:
> ---
> #!/bin/sh
> read myvar
> # do whatever
> ---
I tested and it works great. It seems I have a lot to learn although I
use ssh daily with no problems. <SIGH>
>
> Or do you in fact use a pseudo tty on remote side for interactive mode
> (which would make this a little more difficult)?
>
> If you want to keep your way of doing it, I just have a few hints, but
> didn't test anything, just looked them up out of curiosity:
> - read "man sshd_config", item AcceptEnv, PermitUserEnvironment
I knew about PermitUserEnvironment and SendEnv, but somehow I missed
AcceptEnv... Anyway, AcceptEnv seems to be global, wich is not what I
want.
> - read "man sshd", section LOGIN PROCESS
You lost me here! I can't see relevancy---PermitUserEnvironment allows
to use variables but not to set them from local. Anyway, stdin is the
answer.

Thank you.
>
> -hwh
>

-- 
Jorge Almeida
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [gentoo-user] [OT] Passing env variable to ssh?
  2006-03-13 21:16 ` Mariusz Pękala
@ 2006-03-13 22:44   ` Jorge Almeida
  0 siblings, 0 replies; 5+ messages in thread
From: Jorge Almeida @ 2006-03-13 22:44 UTC (permalink / raw
  To: gentoo-user

On Mon, 13 Mar 2006, Mariusz P?kala wrote:
>
> Stdin?
>
> echo "$myvar" | ssh  myuser@remotebox.org ./bin/mycommand
>
> ?
>
Yup. Thanks!
-- 
Jorge Almeida
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-03-13 22:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-13 20:14 [gentoo-user] [OT] Passing env variable to ssh? Jorge Almeida
2006-03-13 20:36 ` Hans-Werner Hilse
2006-03-13 22:42   ` Jorge Almeida
2006-03-13 21:16 ` Mariusz Pękala
2006-03-13 22:44   ` Jorge Almeida

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox