Two ways to use SSH to secure Internet connections are local port forwarding and dynamic port forwarding. Local port forwarding forwards web traffic from a server, while dynamic port forwarding transforms your SSH client into a SOCKS proxy server. Both can be useful for secure Internet access in insecure environments such as public networks. To use either, you need to be able to login onto a remote system. Both are easy to use.

Local Port Forwarding

Local port forwarding can be used to access specific sites from another machine. For example, to route traffic from www.somewebsite.com on a remote PC (user@yourdomain.com) to port 12345 on a client PC, the following could be entered into a command window:

ssh -L 12345:www.somewebsite1.com:80 user@yourdomain.com<host>

multiple connections may also be combined into one command as follows:

ssh -L 12345:www.somewebsite1.com:80 -L 23456:www.somewebsite2.com:80 user@yourdomain.com<host>

Use:
You just need to open a browser and point it to http://localhost:12345/ to securely access somewebsite1.com or http://localhost:23456/ to access somewebsite2.com.

Note: An IP address can also be used in place of yourdomain.com (e.g. user@192.168.1.1).

Dynamic Port Forwarding

Dynamic port forwarding is even more powerful as it allows you to securely connect to any web page and to bypass firewalls. To set it up, the following could be entered into a command window:

ssh -C -D 23456 user@yourdomain.com
  • The -C is optional and is used to enable compression, which can speed up connections
  • The -D enables dynamic port forwarding
  • 23456 is the port on the client PC

Use:
To use this connection, you will need to configure your browser to use a SOCKS proxy. See the following two articles on how to do this for your browser:

Make Tech Easier – How to Secure Your Internet Connection via SSH

Ubuntu Help - SSHOpenSSHPortForwarding (see Dynamic Port Forwarding section)


Useful Related Articles:

Debian/Ubuntu Tips & Tricks - SSH and Port Forwarding or How to get through a firewall

Linux Magazine – Port Forwarding with SSH

OpenBSD Man Pages for SSH - Manual Pages

Red Hat Magazine – SSH Port Forwarding

University of Victoria – An Introduction to the Black Art of Port Forwarding with SSH

Share

25. May 2011 · 1 comment · Categories: Networking · Tags: ,

This guide illustrates the concepts for tunneling VNC over SSH. VNC is a protocol that allows you to control a desktop from a remote computer and allows others to view or control your desktop from their computer. However, using VNC alone can be a security risk. Although VNC uses password encryption, the rest of the traffic is sent unencrypted.

SSH or Secure Shell, is a secure protocol with a feature called port forwarding that can be used to provide secure connections for VNC, as well as for POP3, SMTP, RDP, HTTP and other protocols. Using SSH port forwarding to secure connections is also known as SSH Tunneling. SSH tunneling creates a SSH tunnel to encapsulate unencrypted traffic (the payload protocol), such as VNC, over an encrypted SSH channel (the delivery protocol). In other words, using VNC with SSH port forwarding makes a port from one PC appear on another PC through a SSH connection, providing a secure path for the VNC traffic.

A practical use of SSH tunneling with local and remote port forwarding would be to securely exchange the desktops between two PCs using the VNC protocol. Setting up the SSH sessions can be accomplished for both PCs from the same SSH client PC. Another use for SSH tunneling not covered in this guide is to bypass firewalls that block certain ports, such as port 80, which are often blocked to prevent users from accessing the Internet using company computers (see related article – Using SSH to secure Internet connections).

SSH Port Forwarding Summary

In the following definitions and examples, a remote machine is defined as the PC with the SSH server. All commands in the examples here are executed from the SSH client machine (192.168.1.1). Although both forwarded and local ports may be the same, the examples shown use different port numbers for clarification.

Two types of SSH port forwarding are: (1) local port forwarding, and (2) remote port forwarding, with local port forwarding being the more common. Another type of SSH port forwarding not covered in this guide, is Dynamic port forwarding (see Using SSH to secure Internet connections).

1.  Local port forwarding –  A port from the client PC is forwarded to the remote PC. A connection to this port enables data to be sent bidirectionally over the SSH connection between the client and remote PC. See Fig 1.

2. Remote port forwarding – This is a reverse of local port forwarding.  A port from the remote PC is forwarded to the client PC.  A connection to this port enables data to be sent bidirectionally over the SSH connection between the client and remote PC. See Fig 2.

Other points:

  • Ports may be forwarded to multiple hosts on a single connection or by using multiple SSH connections.
  • Other computers on the Internet are prevented from connecting to forwarded ports unless enabled with the “-g” flag.
  • VNC servers must allow loopback connections since clients are seen as local connections.
  • To connect PCs over the Internet, port 22 must be forwarded for SSH on the router.
  • Port numbers from 0 to 1023 are privileged ports used by system processes to provide network services. For Unix and Unix-like operating systems, these processes can only execute with superuser privileges. It’s therefore best to avoid using ports under 1024 for local ports.

Local Port Forwarding for VNC

Figure 1 illustrates local port forwarding for a VNC session (click to enlarge) over a LAN. The client Windows PC has IP address 192.168.1.1 and the remote Linux PC has IP address 192.168.1.3.  The syntax for local port forwarding as used in this example:

ssh username@serverhost -L localport:host:remoteport

Note: The use of a Windows PC and Linux machine in the Figure 1 below is for illustration purposes only. The operating systems are irrelevant. What matters is that client PC has a SSH client and VNC viewer, and the remote machine has a SSH server and VNC server. 

Local Port Forwarding

Fig 1

To establish the SSH connection using local port forwarding, the following command can be entered into a command window on the client PC:

ssh user@192.168.1.3 -L 6999:localhost:5901
  • user@192.168.1.3 = SSH host to connect to
  • -L = Option to enable local port forwarding
  • 6999 = Port on the client PC
  • localhost = Host server to connect to (the remote PC, same as 127.0.0.1)
  • 5901 = Port on the remote host (forwarded from the client PC)

To connect to the VNC server, enter the following into the VNC viewer:

127.0.0.1:6999

or

localhost:6999

Remote Port Fowarding for VNC

Figure 2 illustrates remote port forwarding for a VNC session (click to enlarge) over a LAN. The client Windows PC has IP address 192.168.1.1 and the remote Linux PC has IP address 192.168.1.3. The syntax for remote port forwarding as used in this example:

ssh username@serverhost -R localport:host:remoteport

Note: The use of a Windows PC and Linux machine in the Figure 1 below is for illustration purposes only. The operating systems are irrelevant. What matters is that the the client PC has a SSH client and VNC server, and the remote PC has a SSH server and VNC viewer. 

Remote Port Forwarding

Fig 2

To establish the SSH connection using remote port forwarding, the following command could be entered into a command window on the client PC:

ssh user@192.168.1.3 -R 6999:localhost:5901
  • user@192.168.1.3 = SSH host to connect to
  • -R = Option to enable remote port forwarding
  • 6999 =Port on the remote host
  • localhost = Host server to connect to (the client PC, same as 127.0.0.1)
  • 5901 = Port on client PC (forwarded from the remote PC)

(Add the “-v” option at the end of the command above to view debugging messages about SSH’s connection progress)

To connect to the VNC server, enter the following into the VNC viewer:

127.0.0.1:6999

or

localhost:6999
Share
11. May 2011 · 1 comment · Categories: Networking · Tags: ,

This guide demonstrates how to setup OpenSSH RSA public-key authentication for Windows (using OpenSSH v3.8.1p1-1) and Linux (using OpenSSH v5.3p1) PCs currently working with password authentication on a local network. Although the information for this guide was tested on PCs with WinXP and Lubuntu, it can be applicable for other versions of Linux and Windows. You will need physical access to both PCs.

rsakeys

Public-key Cryptography

Public-key cryptography uses of a pair of matching keys, a public key and a private key, which are created at the same time using a key generation utility (ssh-keygen.exe is the key generation utility used in OpenSSH). A public key can be known to anyone and is used to encrypt data. The only way to decrypt data encrypted with the public key is with the matching private key. Although the two keys are related, a private key can’t be created from its matching public key. Public-key cryptography is widely used for public-key authentication to enable secure logins to servers without passwords, and for digital or electronic signatures, which certifies the authenticity of data signed by the private key.

OpenSSH Public-key Authentication

OpenSSH can use either the RSA or DSA algorithms for public-key authentication. RSA stands for stands for Rivest, Shamir and Adleman, the last names of the MIT team members who developed it. DSA stands for Digital Signature Algorithm, a US Government standard proposed by the National Institute of Standards and Technology. Although there are arguments for and against using one or the other, RSA is often the preferred choice because of its verification speed and key strength. See What is better for GPG keys – RSA or DSA? for a discussion on on this topic.

The importance for using pubic key authentication can be summed up in this statement from the Ubuntu help pages: “If your SSH server is visible over the Internet, you should use public key authentication instead of passwords if at all possible. If you don’t think it’s important, try logging all of the malicious login attempts you get for the next week. My computer – a perfectly ordinary desktop PC – had over 4,000 attempts to guess my password and almost 2,500 break-in attempts in the last week alone. “

Steps for RSA Public-key Authentication

The following steps will setup RSA public-key authentication keys without a passphrase to enable automatic logins between Linux to Windows PCs on a local network. The instructions will be similar to setup public-key authentication on remote hosts, except that SSH port 22 (if using the default port) must be forwarded to access remote servers from behind a router. When creating keys without a passphrase, as in this guide, make sure to place the public key on trusted hosts as it’s possible to compromise the remote computer should your private key fall into the wrong hands.

From the Windows PC

Step 1 – Generate Public Keys for the Windows PC

On the Windows PC, open a CMD window and type in the following command and hit ENTER to create a RSA key of 2048-bits (the default). The -t option specifies the type of key:

ssh-keygen -t rsa

Note: If you get a command is not recognized error, your path is incorrect. In this case, change to the bin folder where OpenSHH is installed to run the command.

When the command is executed, you will be prompted for a location to save the keys, and then for a passphrase as shown below. Hit ENTER to accept the default locations and to set NO passphrase.

Output:

Generating public/private rsa key pair
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa
Your public key has been saved in /home/username/.ssh/id_rsa.pub

The public key will be saved as .ssh/id_rsa.pub and your private key saved as .ssh/id_rsa in your home folder. The home directory is setup for users when OpenSSH was installed and configured.

Step 2 – Transfer Public Key to Linux PC

For the public key to be usable, it must be appended to the .ssh/authorized_keys file on the Linux computer and/or on other hosts you log into. If the authorized_keys file does not exist in your Linux computer’s home .ssh directory, create it. The public key (ending in .pub) can be copied to /home/username/.ssh/otherkeys on the Linux computer using a USB drive, another medium, Windows file sharing, or SCP. Make sure to only copy the key and not move it.

After transferring the public key, at the Linux PC, open a terminal window and navigate to the .ssh folder in your home directory, and append the public key using the command below:

cat otherkeys/id_rsa.pub >> authorized_keys

Note: the key can also be cut and pasted into the authorized_keys file using a text editor

OR – copying the key if the authorized_keys file is empty or not present

To remotely copy the public key to the Linux PC using SCP, enter the following in a command window. Note that there is no command for appending to a file using SCP. You will be asked for your password to use SCP remotely from the Windows PC:

# scp ~/.ssh/id_rsa.pub user@192.168.x.x:.ssh/authorized_keys

Step 3 – Edit sshd_config

Open a command window and try to authenticate automatically to the Linux PC from the Windows PC using SSH. Make sure the SSH server was started on the Linux PC. It should work. If not, continue with the rest of this step and then recheck.

To troubleshoot the SSH public-key cryptography authentication processes, you can use the verbose option switch (-v) in the ssh command when logging in:

ssh -v user@192.168.x.x

If authentication didn’t work, goto the Linux PC and check that the permissions of the .ssh directory are set to octal 700. If not, use the following command from the Linux PC to change it:

# chmod 700 ~/.ssh/authorized_keys

If error messages were observed relating to the known_hosts file, find and delete the entries in the known_hosts file in the user .ssh directory of the Windows PC.  The entries causing the errors will be numbered in the error message. After deleting the offending entry in the known_hosts file, test again to determine whether you can log onto the Linux PC without using a password.

After verifying you can log into the Linux PC without using a password, password authentication will still work should RSA not work for any reason, which is a security vulnerability. Password authentication can be turned off completely by changing the following entries in the etc/ssh/sshd_config file on the Linux PC. To use RSA authentication exclusively, make the following changes to the sshd_config to force public-key authentication and disable password authentication:

PasswordAuthentication no
PubkeyAuthentication yes
RSAAuthentication yes

After saving the file, restart the Linux PC SSH server using sudo /etc/init.d/ssh restart from a terminal on the Linux PC before logging in.

____________________________________________________________________________________

From the Linux PC

The steps are essentially the same as the previous steps with a few minor differences from the previous instructions

Step 1 – Generate Public Keys for the Linux Computer

From the Linux PC, open a terminal and type in the following command and hit ENTER to create a RSA key of 2048-bits (the default). The -t option specifies the type of key:

ssh-keygen -t rsa

When the command is executed, you will be prompted for a location to save the keys, and then for a passphrase as shown below. Hit ENTER to accept the default locations and to set NO passphrase.

Output:

Generating public/private rsa key pair
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa
Your public key has been saved in /home/username/.ssh/id_rsa.pub

The public key will be saved as .ssh/id_rsa.pub and your private key saved as .ssh/id_rsa in your home folder.

Step 2 – Transfer Public Key to Windows PC

For the public key to be usable, it must be appended to the .ssh/authorized_keys file on the Windows computer, other Linux PCs, and/or other hosts you log into. If the authorized_keys file does not exist in the user’s Windows .ssh directory, create it. The public key (ending in .pub) can be copied to \home\username\.ssh\otherkeys on the Windows computer using a USB drive, another medium, file sharing, or SCP. Make sure to only copy the key and not move it.

After transferring the public key, at the Windows PC, navigate to the .ssh folder in your home directory, and append the public key to the authorized_keys file using the command below:

copy /b authorized_keys + otherkeys\id_rsa.pub authorized_keys

Note: the key can also be cut and pasted into the authorized_keys file using a text editor

OR – if the authorized_keys file is empty or not present

To remotely copy the public key from the Linux PC to the Windows PC with SCP, enter the following in a terminal window. Note that there is no command for appending to a file using SCP. You will be asked for your password to use SCP remotely from the Linux PC:

# scp ~/.ssh/id_rsa.pub user@192.168.x.x:.ssh/authorized_keys

Step 3 – Edit sshd_config

In a terminal window try to log into the Windows PC with public-key authentication using SSH. Make sure the SSH server was started on the Windows PC. It should work. If not, continue with the rest of this step and then recheck.

To troubleshoot the SSH public-key cryptography authentication processes, you can use the verbose option switch (-v) in the ssh command as follows when logging in:

ssh -v user@192.168.x.x

If error messages errors were observed relating to the known_hosts file, find and delete those entries in the known_hosts file in the user .ssh directory in the Linux PC before continuing. The entries causing the errors will be numbered in the error message.

After deleting the offending entry in the known_hosts file, test again to determine whether you can log onto the Windows PC without using a password.

After verifying you can log into the Windows PC without using a password, password authentication will still work should RSA not work for any reason, which is also a security vulnerability. Password authentication can be turned off completely by changing the following entries in the OpenSSH\etc\sshd_config file on the Windows PC. To use RSA authentication exclusively, make the following changes to the sshd_config file to force public-key authentication and disable password authentication:

Note: If you still are unable to log in with pubic-key authentication at this point, do not make the following changes to the sshd_config file to force public-key authentication since you may need to login locally using your password with tools such as WinSCP. See below troubleshooting procedures:

StrictModes no
PasswordAuthentication no
PubkeyAuthentication yes
RSAAuthentication yes

After saving the sshd_config file, restart the Windows PC SSH server first by stopping it using net stop opensshd and then restarting it using net start opensshd in a command window on the Windows PC to allow the config file to take effect before logging in.

If public-key authentication still doesn’t work, the most likely cause is that that the read/write/access permissions for the .ssh directory or for OpenSSH for the Windows PC are incorrect. See the below troubleshooting procedures below for further information.

Troubleshooting Windows OpenSSH server issues:

File permissions issues are a notorious problem for getting pubic-key authentication to work for OpenSSH on Windows. It’s probably the most confusing and most difficult issue to resolve. After much research and troubleshooting, I got it to work following this source from osdir.com. However, it’s uncertain whether it was one, all, or a combination of the suggestions that fixed the problem. In any case, below is a summary of the suggestions and how they were followed.

The tool used to change file permissions for the instructions below was WinSCP, with 127.0.0.1 as the host name and SFTP as the protocol (see screenshot below).

WinSCP session screen

Permission changes were made using the properties window as shown in the screenshot below:

winscp properties

Here are the suggestions from osdir.com and how each was followed. Suggestions are preceded by an asterisk “*” and how the suggestions were followed are in bold :

*Change ownership of OpenSSH folder/subfolders to Administrators using Windows Explorer – Performed this for the folder and all subfolders using WinSCP.

*Grant Administrators full control of the OpenSSH folder – Same as above using Octal 0700

*From a command prompt, type “cacls c:\program files\openssh /t /e /c /g Administrators:F” * – Performed this for the c:\ssh folder, which was the OpenSSH folder on my PC.

Edit sshd_config file and set StrictModes to “no” –  Changed the StrictModes entry to “no” and saved the file

*Under the user’s profile, grant Administrators (and only Administrators) full control of the .ssh folder and files – Did this for all folders and files for .ssh in the user directory (C:\Documents and Settings\user\.ssh).

*If this folder does not exist, it can be created by establishing an SSH connection to another box – Skipped. The .ssh file already existed

*On clients only, copy the private RSA key to the local .ssh folder and name it “id_rsa” - Skipped. The private keys already existed.

*Copy the client’s public RSA key to the desired server(s) by adding it to an “authorized_keys” text file located under the server’s .ssh folder - Skipped. Done previously.

* To use publickey authentication, use the SSH command line switch “-o PreferredAuthentications=publickey”. Alternately, you can modify the ssh_config file to make this the default – Skipped.

If the above instructions worked:

Decide whether to use RSA authentication exclusively. If so, edit the sshd_config file per the instructions above.

Note: many instructions on various web sites suggest copying public keys to the user’s .ssh directory on the server. If you do, make sure to place them in a separate folder such as a otherkeys folder or another name such as username_key since existing public keys (id_rsa.pub) will be overwritten if multiple PCs are used to access the same machine. 

Share
03. May 2011 · Write a comment · Categories: Networking · Tags: ,

VNC is one of many protocols used to share desktops between Linux and Windows PCs (see this Wikipedia entry for a comparison of various remote desktop software packages). Although a number of VNC (Virtual Network Computing) servers include some type of built-in encryption, many do not. In addition, many VNC client/viewers tend to be basic so they generally don’t include any built-in encryption support. For both aforementioned situations, SSH tunneling can be used to secure sessions between VNC servers and even the most basic VNC client/viewers, regardless of any built-in protocols. However, using SSH to encrypt VNC communications can be a manually intensive and multi-step process requiring starting up SSH and VNC servers and configuring SSH and VNC clients for local or remote port forwarding.

An Enhanced TightVNC Viewer, SSVNC, is free multi-platform SSH/SSL VNC viewer that automates this process. It’s also compatible with a wide range of VNC servers. In fact, the SSVNC web site states that SSVNC works with nearly any VNC Server host running SSHD and those running an SSL tunnel, including VeNCrypt SSL/TLS and Vino/ANONTLS encryption extensions to VNC on Unix, Mac OS X, and Windows. SSVNC also works as a regular VNC viewer without encryption as well. SSVNC is available from the Ubuntu repositories and installable through the Synaptic Package Manager or apt-get, while Unix, MacOS, and Windows versions are available from the SSVNC web site and through Sourceforge.net.

SSVNC Viewer

For this post, SSVNC (using the precompiled binaries) was tested on a Windows XP machine connected to TightVNC and X11VNC servers running on a Lubuntu machine and SSH tunneling enabled through the SSVNC viewer. Although this viewer is packed with features, it worked quickly and easily. Its many features are listed on the SSVNC web site.

viewer interface

Related Information:

VNC on Linux

 

Share
23. February 2011 · 4 comments · Categories: Networking · Tags:

This guide explains how to install and configure a SSH server for a Windows XP home computer. SSH (Secure Shell) is a secure communications networking protocol based on the client-server model. It’s used to log into and execute commands between remote computers or devices and is widely used as a secure replacement for the insecure telnet and rlogin protocols. SSH encrypts all of the data, including the authentication data, allowing secure communications over unsecured networks, such as the Internet. Connections are made using public-key cryptography or password authentication while the data itself is encrypted using one of several included encryption algorithms. It supports tunneling, port forwarding and transferring files with the associated protocols SFTP (Secure File Transfer Protocol) and SCP (Secure Copy Protocol), which are part of the standard SSH package. Typically used on Linux and UNIX systems, SSH runs on Windows systems using Linux-like environments such as Cygwin.

Benefits of SSH

  • Enhanced Security – user and host authentication, data encryption and integrity
  • Remotely connect computers (running Windows or Linux) and execute commands
  • Use applications such as Filezilla or WinSCP for file management operations on the same computer or from a remote computer
  • TCP/IP and X11 connection tunneling (a slightly more complex topic not explained in this guide)

The OpenSSH package

This guide uses the free and precomplied version of the OpenSSH suite, a stand alone version of SSH using a stripped down version of Gygwin. This allows for a quicker and smaller installation than if OpenSSH is installed as part of a regular Cygwin installation. The OpenSSH suite consists of the SSH program, SCP, SFTP and it also includes several supporting utilities (see http://openssh.org). The Windows version of OpenSSH hasn’t been updated for sometime, so the latest pre-compiled version available for Windows is v3.8.1p1-1 (July 2004), which still works well. See http://sshwindows.sourceforge.net/ for more information. For this guide, the SSH server is setup for password authentication.
______________________________________________________________________________

Step 1: Install OpenSSH

  1. Download OpenSSH for Windows v3.8.1p1-1. This is the direct download link
  2. Unzip the archive and then run the installer setupssh.exe
  3. Change the installation location to “C:\OpenSSH” instead of program files to avoid spaces in directory names
  4. Use the default settings as shown on the screen-shot below
  5. Done with the installation. However, the SSH server’s passwd file must be configured before use.
openssh install screen

OpenSSH installation options

Step2: Configure OpenSSH

  1. On your computer, click Start–> Run–> Type in “cmd” (without quotes), and then hit the OK button.
  2. In the command window, cd to the “OpenSSH\bin” folder.
  3. (Optional step) OpenSSH uses port 22 by default. If for some reason you need to use another port, you can change the port assignment for OpenSSH to prevent port conflicts. In the command window, cd to “OpenSSH\etc\sshd_config” and change the following line (approx line 13 in the file – a text editor can also be used):

    Port 22
    to:
    Port 5704

    (note that “#” needs to be removed to change the port assignment. Any other unused port other than 5704 is also OK)

    Save the file
  4. Enter the following in the command window. In the following commands, -l indicates local and -d indicates domain. Press Enter after each line; don’t include quotes:
    1. “mkgroup -l >> ..\etc\group”
      1. Creates a group file for local user accounts
    2. “mkgroup -d >> ..\etc\group” (skip – not normally required)
      1. Creates a group file for domain users. Returns [2453] if there is no PDC – primary domain controller
      2. Most instructions state to run both of the above commands. However, the “OpenSSH\readme.txt” file in “OpenSSH\doc” states: “If you use both mkgroup commands, the group file will contain duplicates. You will need to remove these by hand in a text editor.” Kind of confusing, but when both are executed I got the [2453] error for -d, but it didn’t change anything in the group file.
    3. “mkpasswd -l -u username >> ..\etc\passwd”
      1. Adds a local authorized user to passwd file for local user accounts. NOTE: Omitting the username switch adds ALL users from the machine or domain, including service accounts and the Guest account.
    4. “mkpasswd -d -u >> ..\etc\passwd” (skip – not normally required)
      1. Adds passwd file for all domain user accounts. Returns [2453] if there is no domain controller
      2. Again, if you get the [2453] error with the -d switch above, it doesn’t apply and won’t change anything in the passwd file.
  5. Enter net start opensshd to start the SSH server. It’s installed as a service, so in the future, the server will automatically start each time the computer boots.
  6. The SSH server is now configured with password authentication (the default configuration). If you want to use public key authentication, you need to generate public and private keys using the supplied executable and change the sshd_config file.  Note that the “OpenSSH\keyauthentication.txt” file in the “OpenSSH\docs” directory states: “This document is outdated. You can use this as a reference, but please don’t expect it to be accurate. I will update this soon.” In any case, it shouldn’t be too difficult to accomplish public key authentication using the “OpenSSH\keyauthentication.txt” and with some other references. Some sources explaining how to setup public-key authentication for OpenSSH are below:

    OpenSSH RSA Authentication for Windows and Linux

    ssh-keygen Tutorial – Generating RSA and DSA keys

    OpenSSH for Windows
  7. Done with configuration. Next, testing the SSH server.

    configure ssh in command window

    SSH server configuration

Test the installation on the SSH server (from the same machine)

  1. Enter ipconfig in the command window to find your ip address.
  2. Enter ssh yourusername@192.168.x.xxx or ssh yourusername@servername (servername = computername) into the command window to login using SSH. You can also use any of the login options listed at the end of this page for logging in using a command window on the PC with the SSH server.

    Note: You may get a usage warning screen as shown below. If so, ignore it and sign in with your password. Also note that if you are logging in to the server for the first time, depending on the application being used to connect, you may also get another warning similar to: “The server’s host key was not found in the cache. You have no guarantee …blah blah… rsa2 key fingerprint is: ssh-rsa 1024 95:3c:9e:2b:23:df:bd:57:b4:ad:f1:5f:4c:2f:9c:ba
    “. This warning can also be safely ignored if you know the SSH server is the correct one you intended to log into. The warning is an anti-spoofing technique where each server is given a unique host key to prevent it from imitating another server. The technique is explained in detail on the WinSCP web site.
  3. It’s working if you get the screen below. Next, some optional tweaking for changing the home directory.
ssh logon warning screen

SSH login warning screen

Optional Tweaking

Changing the Home Directory within Documents and Settings for user(s):
By default all user home directories are set to (/home/username) in the passwd file in the “OpenSSH\etc” directory, where (/home) corresponds to “C:\Documents and Settings” for Windows XP. This is somewhat inconvenient since most users may want to start in “My Documents”. To change it, open the passwd file in a text editor and change the second to last entry from “/home/username” to “/home/username/My Documents” and save. Entries are separated by a colon “:”  for each user and are located just before the “/bin/switch” entry (switch stands for switch.exe, which enables both scp/sftp and the SSH standard command prompt to be available by switching between them).

Changing Home to outside the default directory on the SSH Server
To place users outside the default directory for their Windows profile, you need to change the directory that (/home) corresponds to by editing the value of the “native” key in the registry under (HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/home). The value of “native” corresponds to the (/home) directory in the passwd file. For instance, if the “native” entry is changed to C:\Users, then all users will be placed under separate folders in that directory — e.g., C:\Users\username1, C:\Users\username2, etc. If you then change each user (/home/username) in the passwd file to just (/home), this puts those users under C:\Users. If you have a subdirectory such as “C:\Users\OpenSSH”, you can place users there by changing the entries in the passwd file to (/home/OpenSSH).

Note that changing the home directory using this method works only for logins (Passwd), and doesn’t work for for SCP or SFTP. Instead, use Cygdrive Notation to change the directory for using Passwd, SCP, and SFTP (explained in next paragraph).

Registry entry to change default directory

HKEY_LOCAL_MACHINESOFTWARECygnus SolutionsCygwinmounts v2/home

Changing the Drive of the Home Directory when using Passwd, SCP, and SFTP (Cygdrive Notation)
To access any folder on any drive letter outside the installation root (/home), a special notation called Cygdrive is required when using SCP, SFTP and for the home directory entries in passwd. Cygdrive notation changes the mapping of drive letters by mapping them into a UNIX-style file-system. Cygdrive notation overrides all other settings in the registry.

To use, add “/cygdrive/driveletter” to the start of the folder path in the user passwd file and/or when using the SCP or SFTP commands. For instance, to change to the “C:\windows\system” directory in a command window use: “cd /cygdrive/c/windows/system. To transfer file example.txt to d:\test using SCP, the command would be “scp example.txt  user@localhost:/cygdrive/d/test/“.

You can even change the prefix of cygdrive notation by adding two entries to the registry. Open HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2, and add a REG_DWORD called “Cygdrive flags” and set it to 2a hex. Then add a REG_SZ called “Cygdrive prefix” and set its value to the new prefix. For instance, if you set it to “/” then the C: drive becomes accessible using Cygdrive notation “/c”, the D: drive with “/d”, or the F:\test folder with “/f/test” and so forth. If it’s set to “/foo”, then the C: drive becomes accessible using Cygdrive notation “/foo/c”, the D: drive with “/foo/d”, or the F:\test folder with “/foo/f/test” and so on. This behavior can be tested in a command window using the command “mount –change-cygdrive-prefix /foo” before permanently changing the registry.

______________________________________________________________________________

Remote connections from the network

To connect to the SSH server from a remote computer on the network, a SSH compliant client is needed. SSH is usually installed by default on Linux systems, and clients such as Putty are often included as well. If the remote computer will be a Windows machine, it needs to have at least the Cygwin or OpenSSH client installed in order to connect with the SSH server from a command window, while Putty is a stand-alone application. The client portion for OpenSSH can be installed separately during the OpenSSH installation process. The installation process sets the path variable for the OpenSSH client and/or Server, so that SSH commands are available from any command window on that machine. Even with an OpenSSH or Cygwin client installed, it’s a good idea to have a client like Putty also installed, because it makes connecting much simpler.

Connecting from the outside world

To connect to the SSH server from the outside world, you need to port forward port 22 (or the port set during the OpenSSH installation) to the router. Port forwarding can be setup with a program like SimplePortForwarding or by following instructions in the router user’s manual. This sets up the router to forward any connection to port 22 to the SSH server. Then, all that’s needed to connect is to use a client like Putty from any computer connected to the Internet and the public IP address for your router.

Using Filezilla, WinSCP and Putty

Client utilities such as Filezilla, WinSCP, and Putty can be used on the computer with the SSH server, from remote computers on the LAN, and from the outside world to connect to the SSH server. When using any of these utilities on the SSH server machine, you can use 127.0.0.1, computername, or localhost as the IP along with the user and password info used to login to that account. Use the SFTP protocol for Filezilla, the SCP or SFTP for WinSCP, and SSH for Putty. The beauty of using WinSCP or Filezilla on a SSH server machine is that file tasks like changing permissions with CHMOD are possible for any files, such as local installations of your web sites. In other words, unlike natively installed servers, such as a FTP server, the SSH server and applications using the server can run on the same machine without any loss of functionality since the SSH server runs in a separate environment (Cygwin) using the loopback interface.

filezilla setup screen

Localhost login with Filezilla

putty config screen

Putty config screen (hostname can also be localhost or 127.0.0.1)

winscp config screen

Localhost login with WinSCP

List of connecting options from command window and applications:

Using a Command Window:

Password will be the same as the user password for that machine (commands are case sensitive)

  • On the SSH server:
    • ssh yourusername@192.168.x.xxx
    • ssh yourusername@127.0.0.1
    • ssh yourusername@localhost
    • ssh yourusername@servername
  • Remote computer on the network with SSH client installed:
    • ssh yourusername@192.168.x.xxx
    • ssh yourusername@servername
  • Remote computer from outside world with SSH client installed:
    • ssh yourusername@xxx.xxx.x.xxx:port (remote ip address for your router set with port forwarding)

Using client applications such as Putty, WinSCP or Filezilla

User Name and Password will be the same as the user login credentials for that machine

  • On the SSH server:
    • IP Address: 127.0.0.1, localhost, servername, or 192.168.x.xxx
  • Remote computer on the network:
    • IP Address: servername or 192.168.x.xxx
  • Remote computer from outside world:
    • IP Address: xxx.xxx.x.xxx (remote ip address for your router set with port forwarding)

______________________________________________________________________________

Using SSH commands other than for connecting is another topic and not covered in this guide; however, a few are explained at the following:

The Geek Stuff5 Basic Linux SSH Client Commands

GAMEXE.NETA Beginner’s Guide to SSH

Leonard Austin –  SSH Commands

 

Share

Bad Behavior has blocked 373 access attempts in the last 7 days.