Archive

Posts Tagged ‘SSH’

Reverse SSH Tunnelling

May 13, 2008 3 comments

It is possible to create a “reverse” SSH Tunnel. The reverse tunnel will allow you to create an SSH Tunnel from your work computer to your home computer, for example, and then login to your work machine from your home machine even if your work firewall does not permit ssh traffic initiated from your home machine!

For this to work, an SSH Server must be installed on your work and home computer, and ssh (TCP port 22) must be allowed outbound from your work computer to your home computer.

Syntax: ssh -R remote_port:localhost:22 your_home_computer

At home, you would then run ssh -p 2048 localhost to log into your work computer via ssh.

Here is a script that you can run through the cron facility on your work system to make sure the reverse SSH Tunnel to your home system is up and running. It is useful in case the system is rebooted.

#!/bin/sh

# $REMOTE_HOST is the name of the remote system
REMOTE_HOST=remote.system.ip

# $REMOTE_PORT is the remote port number that will be used to tunnel
# back to this system
REMOTE_PORT=5000

# $COMMAND is the command used to create the reverse ssh tunnel
COMMAND=”ssh -q -N -R $REMOTE_PORT:localhost:22 $REMOTE_HOST”

# Is the tunnel up? Perform two tests:

# 1. Check for relevant process ($COMMAND)
pgrep -f -x “$COMMAND” > /dev/null 2>&1 || $COMMAND

# 2. Test tunnel by looking at “netstat” output on $REMOTE_HOST
ssh $REMOTE_HOST netstat -an | egrep “tcp.*:$REMOTE_PORT.*LISTEN” \
> /dev/null 2>&1
if [ $? -ne 0 ] ; then
pkill -f -x “$COMMAND”
$COMMAND
fi

Advertisements

SSH Tunnelling

May 13, 2008 Leave a comment

SSH Tunnelling is an excellent way to tunnel insecure protocols through a secure communication channel. In this example, I’ll tunnel POP3 traffic using SSH. Traditional POP3 traffic, including username and password information, travels clear-text across the network.

The syntax: ssh -f -N -L <local port>:<remote server>:<remote port> <userid>@<remote server>

To tunnel POP3 traffic using ssh:

  1. Make sure an ssh client is installed on your machine and an ssh server is installed on the POP3 server.
  2. Create a local SSH Tunnel on your machine (port 1234 for this example) to the POP3 server’s port 110. You will need to be the root user to bind to “privileged” ports (< 1024).
    # ssh -f -N -L 1234:localhost:110 user@POP3_server
  3. Test the tunnel.
    $ telnet localhost 1234
    You should see the POP3 server’s banner information.est the tunnel.
  4. Configure your mail client to access your mail via POP3 using mail server localhost and port 1234.

Using OpenSSH keys with SSH.com Server

February 27, 2008 Leave a comment

You can determine which versions of the ssh protocol an ssh server supports by examining the service banner. The service banner includes both the remote protocol version and the remote software version.

Example:
telnet ssh_server 22

SSH-1.5-remote_software_version (supports ssh protocol 1 only)
SSH-1.99-remote_software_version (supports ssh protocols 1 and 2)
SSH-2.0-remote_software_version (supports ssh protocol 2 only)

ssh protocol 2:

1. Create a DSA or RSA key named foo. As of version 3.0 of the ssh.com server includes support for RSA keys.
$ cd ~/.ssh
$ ssh-keygen -t dsa -f foo

2. Convert the DSA or RSA key into “SECSH Public Key File Format,” the format used on an ssh.com server.
$ ssh-keygen -e -f foo > foo.pub

3. Copy the foo.pub file to the ssh.com server.
$ scp foo.pub user@ssh.com_host:.ssh2

If the remote server only allows ssh protocol 2, you may receive the following errors:

scp: warning: Executing scp1 compatibility.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
lost connection

Use sftp instead to transfer the key:

$ sftp user@ssh.com_host
put foo.pub .ssh2

4. Add the appropriate ~/.ssh2/authorization file entry in the ssh.com server.
$ ssh user@ssh.com_host ‘echo “key foo.pub” >> .ssh2/authorization’

5. Login to the ssh.com server using the foo identity.
$ ssh -o IdentityFile2=~/.ssh/foo user@ssh.com_host

ssh protocol 1:

1. Create an RSA1 key.
$ cd ~/.ssh
$ ssh-keygen -t rsa1

2. Append the ~/.ssh/identity.pub file to the ~/.ssh/authorized_keys file on the ssh.com server.
$ cat ~/.ssh/identity.pub | ssh remote_server “cat – >> ~/.ssh/authorized_keys”

Note: Any ssh.com server only allowing ssh protocol 1 should be upgraded, as usage of ssh protocol 1 itself is not recommended.

SSH: Convert OpenSSH to SSH2 and vise versa

December 14, 2007 31 comments

Connecting two server running different type of SSH can be nightmare if you does not know how to convert the key. In this tutorial, I will try to explain on how to convert the public key from OpenSSH to SSH2 and SSH2 to OpenSSH. To convert the key, it must be done in OpenSSH server.

Convert OpenSSH key to SSH2 key

  • Run the OpenSSH version of ssh-keygen on your OpenSSH public key to convert it into the format needed by SSH2 on the remote machine. This must be done on the system running OpenSSH.
    #ssh-keygen -e -f ~/.ssh/id_dsa.pub > ~/.ssh/id_dsa_ssh2.pub

Convert SSH2 key to OpenSSH key

  • Run the OpenSSH version of ssh-keygen on your ssh2 public key to convert it into the format needed by OpenSSH. This needs to be done on the system running OpenSSH.
    #ssh-keygen -i -f ~/.ssh/id_dsa_1024_a.pub > ~/.ssh/id_dsa_1024_a_openssh.pub

Read more…

SSH/SSH2 Password-less Authentication

October 17, 2007 11 comments

A great little guide to setting up two accounts so that you don’t have to type in your password when sshing between them. btw, OS X uses OpenSSH. I don’t know what it is for other platforms.

Basic Idea

No-password authentication works because of public key crypto. Let’s say you have a local machine Ooga and a remote machine Booga. You want to be able to ssh from Ooga to Booga without having to enter your password. First you generate a public/private RSA key pair on Ooga. Then you send your public key to Booga, so that Booga knows that Ooga’s key belongs to a list of authorized keys. Then when you try to ssh fromOoga to Booga, RSA authentication is performed automagically.

Here are detailed steps on how to do this.

NOTE: The following examples and scenarios assume you are creating only a single key, e.g. one RSA key or one DSA key. If it turns out that you’ve created both keys on your (client) system, then you will need to send both of them to the SSH/SSH2 server; otherwise, you may still be asked to enter a passphrase. Read more…

How to make SSH2 work with OpenSSH

October 17, 2007 6 comments

The commercial version of SSH2 uses a different key format than the OpenSSH. This guide shows how to make them inter-operate with each other with public key authentication. Read more…

%d bloggers like this: