VNC and SSH for portforwarding

Posted on

The problem: There is only a Windows PC with a Internet connection and you need to connect to some unix machines behind this machine with ssh, HOW?

The solution: Use a VNC (e.g.: TightVNC) and OpenSSHD for Windows on your Linux box.

Detail description:

Pre required components:

  1. A VNC Client, I have used the vncviewer from TightVNC
  2. OpenSSHD for Windows
  3. Admin access to the Windows machine

OK now we can start with the necessary steps.

Windows Part

1.) Install TightVNC on your Windows machine.

2.) Install OpenSSHD on your Windows machine.

3.) Read the quickstart.txt from OpenSSHD.

Here the part which I think ist the most important one:

Configuration
1.  Open a command prompt and change to the installation directory
    (Program Files\OpenSSH is the default).
2.  CD into the bin directory.
3.  Use mkgroup to create a group permissions file. For local
    groups, use the "-l" switch. For domain groups, use the
    "-d" switch.
    For both domain and local, it is best to run the command twice
    (remember to use >>, not >). If you use both, make sure to edit
    the file to remove any duplicate entires.
    mkgroup -l >> ..\etc\group      (local groups)
    mkgroup -d >> ..\etc\group      (domain groups)
4.  Use mkpasswd to add authorized users into the passwd file. For
    local users, use the "-l" switch. For domain users, use the
    "-d" switch.
    For both domain and local, it is best to run the command twice
    (remember to use >>, not >). If you use both, make sure to edit
    the file to remove any duplicate entires.

    mkpasswd -l [-u <username>] >> ..\etc\passwd      (local users)
    mkpasswd -d [-u <username>] >> ..\etc\passwd      (domain users)

    NOTE: To add users from a domain that is not the primary domain
          of the machine, add the domain name after the user name.
    NOTE: Ommitting the username switch adds ALL users from the
          machine or domain, including service accounts and the
          Guest account.

5.  Start the OpenSSH server.

       net start opensshd

6.  Test the server. Using a seperate machine as the client is best.
    If you connect but the connection immediately gets dropped,
    reboot the machine with the server and try connecting again.

Pay attention that you have a Windows user with a password. This password will be used for the SSH connection.

4.) Start TightVNC and go to the Properties.

5.) Switch to the Administration tab and activate the loopback connections

tightvnc options

6.) Now we are done on the Windows PC

Linux Part

1.) Install TightVNC on your unix / linux machine.

2.) Start a shell

3.) Type in the target server as SECOND -L

(this must be in one line!)

export VNC_VIA_CMD=’/usr/bin/ssh -f -L %L:%H:%R -L 4711:<DESTINATION_SERVER_IN_THE_REMOTE_LAN>:22 <WINDOWS_USERNAME>@%G sleep 20′

4.) Connect to the Windows connected PC with vncviewer

(this must be in one line!)

echo <YOUR_TIGHT_VNC_PW>|vncviewer -compresslevel 4 -quality 4 -bgr233 -autopass -via <IP_OF_THE_INTERNET_CONNECTED_PC> <IP_OF_THE_INTERNET_CONNECTED_PC>

e.g.:

echo aaa|vncviewer -compresslevel 4 -quality 4 -bgr233 -autopass -via 192.168.1.41 192.168.1.41

5.) Now you can connect via port 4711 to the <DESTINATION_SERVER_IN_THE_REMOTE_LAN>

ssh -p 4711 127.0.0.1

EH Voila we are now connected to the remote site ๐Ÿ˜‰
Here a picture because its easier to understand ๐Ÿ˜‰

Connection Flow

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s