Creating a SSH Tunnel

Posted by | Posted in Command-Line, Guides, Linux, OS X, Server, SSH, Tunneling, Ubuntu | Posted on 01-02-2011

To traverse firewalls that block incoming SSH connections or to access a computer with a non routable IP address, you can create an SSH tunnel. When creating a SSH tunnel, you’ll generate the tunnel on the host system and connect it to another system.

With the SSH command, you’ll use the “-R” flag, that allows reversible communications or a reverse tunnel.

This command that I normally use:

It states, create a reversible SSH tunnel from this localhost port 22 to USER@SERVER on port 10000.

 
/usr/bin/ssh -R 10000:localhost:22 USER@SERVER

You’ll need to leave this connection open otherwise the tunnel will collapse. Normally I execute a program at the other end to keep the connection alive. Some SSHd configurations will drop connections due to inactivity.

To connect to the tunnel from USER@SERVER:

use ssh to connect to your USER account on the host server via port 10000.

 
/usr/bin/ssh USER@localhost -p 10000

this will give you the login prompt at the host server. User your login information or you can also setup SSH Keys.

How to use scp – Ubuntu

Posted by | Posted in Command-Line, Linux, Ubuntu | Posted on 17-07-2009

I am currently switching web servers at work from a physical server to a virtual server. The differences are for a different topic, but during this switch, I am going to be copying files from my old server to my new one. Normally you’d copy your files down to your local computer, lets say your laptop or desktop, before upload them to your new server. The not only takes a lot of time, but also eats up hard drive space. I am going to show you how to copy directly from one server to another.

I am going to use SSH’s SCP application. /usr/bin/scp – secure copy (remote file copy program).

For general discussion, I am already remotely logged into my old server via SSH and I have the files that I want to transfer up already TAR’d up. I’ll cover SSH and TAR in later posts. But for right now, I am just going to demonstrate how you should use SCP.

The usage format to transfer a file “up” to another system normally looks something like this.,

/usr/bin/scp /path/to/local.file user@server.address:/path/to/new/location.file

I am going to copy a mysql (database) file from my old server’s backup directory to my home directory on the new server

/usr/bin/scp /backups/mysql_database_dump.sql.tar dmccoy@new.server.com:~/
dmccoy@new.server.com's password: 
mysql_database_dump.sql.tar              100%  391MB   6.4MB/s   01:01

Now, if I wanted to copy a file from my new server to my old server, while still on my old server, I would reverse the sequence.

scp dmccoy@new.server.com:/path/to/mysql_database_dump.sql.tar /path/to/new/location/
dmccoy@new.server.com's password: 
mysql_database_dump.sql.tar              100%  391MB   6.4MB/s   01:01

Family Commands of scp are

/usr/bin/rcp - alias of scp - secure copy (remote file copy program)
/usr/bin/sftp - secure file transfer program
/usr/bin/ssh - OpenSSH SSH client (remote login program)
/usr/bin/ssh-add - adds RSA or DSA identities to the authentication agent
/usr/bin/ssh-agent - authentication agent
/usr/bin/ssh-keygen - authentication key generation, management and conversion
/etc/ssh/ssh_config - OpenSSH SSH client configuration files
/usr/sbin/sshd - OpenSSH SSH daemon

Join the mailing list

Check your email and confirm the subscription