running shell command through ssh tunnel

Matthew Seaman m.seaman at
Sat Dec 27 16:47:43 UTC 2008

Lowell Gilbert wrote:
> Noah <admin2 at> writes:
>> I am trying to run a shell command to the host at the far end of an ssh
>> tunnel.   Here is how I structured access.  Is there any way to do this
>> more compactly on one line?
>> ssh -L 12345: noah at
>> ssh -p 12345 localhost 'chown -R noah:noah /shares/internal/Music/'
> Maybe I haven't had enough coffee yet, but wouldn't that just be
> ssh noah at 'chown -R noah:noah /shares/internal/Music/'
> ?  You might even want to use '-n' as an option to the ssh command.

ENOCOFFEE.  Your equivalence is only the case if you're already logged
into ''  This is a fairly standard idiom for tunnelling a network
connection in through a NAT gateway or a firewall from an external Internet
site to a protected RFC 1918 internal back-end, although the forwarded protocol
is usually other than SSH.

Given that the OP is wanting to tunnel SSH through SSH, a one-liner to
achieve his desired effect might be something like:

ssh noah at ssh noah at chown -R noah:noah /shares/internal/Music/



Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP:     Ramsgate
                                                  Kent, CT11 9PW

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url :

More information about the freebsd-questions mailing list