Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Perl, SSH port forwarding, and secure VNC

by xorl (Deacon)
on Feb 21, 2005 at 20:04 UTC ( #433160=perlquestion: print w/replies, xml ) Need Help??

xorl has asked for the wisdom of the Perl Monks concerning the following question:


I'm trying to write a script that sets up ssh -L x:localhost:y remotehost

without me typing my password on remotehost. I know Net::SSH:Perl will let me login without me having to type my password at run time. However I don't see where I can pass more options (specifically the -L option) to ssh.

This is only one part of the script. I'm trying to automate a secure vnc connection. I'm using the info at Basically once I get the SSH port forwarding done, I'm just going to do an exec("vncviewer localhost").

So maybe I should have started this post with - "Is this the best way to set this up?"

Thanks in advance.

Replies are listed 'Best First'.
Re: [OT] Perl, SSH port forwarding, and secure VNC
by davis (Vicar) on Feb 21, 2005 at 20:57 UTC
    You can do it without perl. Create an ssh publickey and copy it into remotehost's ~/.ssh/authorized_keys. This avoids using any password at all (and is actually more secure in some respects). then you can do:
    ssh -L 5900:vnctarget:5900 remotehost
    and then
    vncviewer localhost
    will get you VNC access to vnctarget. Just tested it.

    It wasn't easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
      just want to add that this also requires setting the sshd configuration to allow this, check the /etc/ssh/sshd_config, turn on: RSAAuthentication, PubkeyAuthentication
        Yes this is correct. I aparently already had that turned on for some other reason.

      Note that if you connect to localhost, VNC will assume you have a fast link and will disable all compression. That can make things very slow if the remote host is not on a LAN with the local machine, in which case you'll have to supply the appropriate -encodings to get a semblance of speed.

      Note also that with TightVNC, you can avoid the ssh -L / -encodings dance by simply saying

      vncviewer -via remotehost vnctarget

      Makeshifts last the longest.

      Ah Cool. It does work! Thanks.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://433160]
Approved by sgifford
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2019-12-12 14:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found