SEARCH

How-To Geek

5 Cool Things You Can Do With an SSH Server

image

SSH offers more than just a secure, remote terminal environment. You can use SSH to tunnel your traffic, transfer files, mount remote file systems, and more. These tips and tricks will help you take advantage of your SSH server.

SSH doesn’t just authenticate over an encrypted connection – all your SSH traffic is encrypted. Whether you’re transferring a file, browsing the web, or running a command, your actions are private.

SSH Tunneling

SSH tunneling allows a remote SSH server to function as a proxy server. Network traffic from your local system can be sent through the secure connection to the SSH server. For example, you could direct your web browsing traffic through an SSH tunnel to encrypt it. This would prevent people on public Wi-Fi networks from seeing what you’re browsing or bypass website and content filters on a local network.

Of course, the traffic becomes unencrypted when it leaves the SSH server and accesses the Internet. To a web server you access through the tunnel, your connection will appear to be coming from the computer running your SSH server, no the local system.

On Linux, use the following command to create a SOCKS proxy at port 9999 on your local system:

ssh -D 9999 -C user@host

image

The tunnel will be open until your SSH connection terminates.

Open your web browser (or other application) and set the SOCKS proxy to port 9999 and localhost. Use localhost because the tunnel entrance is running on your local system.

image

We’ve also covered using PuTTY to set up an SSH tunnel on Windows.

SCP File Transfers

The scp, or secure copy, command allows you to transfer files between a remote system running an SSH server and your local system.

For example, to copy a local file to a remote system, use the following syntax:

scp /path/to/local/file user@host:/path/to/destination/file

image

To copy a file on a remote SSH server to the local system, use this syntax instead:

scp -r user@host:/path/to/remote/file /path/to/destination/file

You can also set up passwordless scp access and use scp to transfer files from within scripts.

Mounting Remote Directories

You can mount a remote folder over SSH and access it like any other directory on your system, skipping the tedious scp process for file transfers.

If you’re using Ubuntu or another GNOME-based desktop environment with the Nautilus file manager, launch the file manager, click the File menu and select Connect to Server.

image

You’ll be prompted to enter the SSH server’s details and your credentials.

image

The files on the remote system will appear in your file manager.

image

Other Linux desktop environments may have similar options to easily mount a directory over SSH.

If you don’t have access to a GUI or would rather use a terminal utility, you can use sshfs to mount the remote SSH system as a file system on your computer.

Preserving Terminal Sessions

Every time you log in with SSH, you’ll be presented with a new terminal session. When you log out, your session will be closed. If you’d rather preserve a terminal session between SSH sessions, use GNU Screen or an alternative utility.

After logging into the remote system, run the screen command to launch a screen session. Run commands within the screen session, and then press Ctrl-a and then d to detach from the screen session.

The screen session and the commands running inside it continue to run in the background. To reattach to the screen session later, run the screen -r command.

SSH can accept commands to run when you log in, so you can connect to an SSH server and reconnect to a screen session with a single command:

ssh -t user@host screen -r

image

If you have local access to the system running the SSH server, you can move between accessing the screen session locally and remotely.

Visualizing Key Fingerprints

When you connect to your SSH server from another system, you’ll see a warning message if the system doesn’t already know its key. This message helps you ensure the remote system isn’t being impersonated by another system.

image

However, you may have trouble remembering the long string that identifies the remote system’s public key. To make the key’s fingerprint easier to remember, enable the “visual host key” feature.

You can enable this in your SSH config file or just specify it as an option while running the SSH command. For example, run the following command to connect to an SSH server with VisualHostKey enabled:

ssh -o VisualHostKey=yes user@host

image

Now you’ll only have to remember the picture, not a long string.


Do you have any other tips to share? Leave a comment and let us know.

Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

  • Published 05/25/12

Comments (16)

  1. Neo Anderson

    link for windows? or you guys havent covered that yet have you?

  2. Jim

    This is just the tip of the iceberg too. SSH is such a great thing for us IT nerds :)

  3. Jim

    @Neo

    Bitvise WinSSHD

  4. Herman Bos

    Usind ssh already for many years, but also when using Windows as a client…. Look in to putty as your client. Very happy with this. Also the pageant client together with the key support.

    No simple passwords on the networks anymore… use key support, and with disabled password supprt no logins possible by other users. One tip do not tweak the timers to much…
    This disabled me to login to my server when i was in Beijing in te past (server is in Holland ‘-) latency was +1000ms! But when i was able to log in…. first i did was changing these timers… (this solved these problems ‘-)

  5. Jeremy

    I think I’d rather remember the string of characters than that crazy image.

  6. Todd

    From the article:
    “We’ve also covered using PuTTY to set up an SSH tunnel on Windows.”

  7. k4rizmz

    @ Neo & other windows users

    Use Cigwin!! There are many cigwin packages like whois, host, tar, gzip, scp and a lot more! Very handy to have.

    You will have to make sure and install the package for ssh but it gives you other great linux tools in a windows environment. Its not perfect but still works great! Once I’m SSH’d into a different server all the tools I need are there anyways.

  8. Grant

    I use an application called FolderSync on my Android phone in conjunction with SFTP and DynDNS.org. Works a little like Dropbox, except that all of the data is all on my own machine, so I don’t have the space limitations or annoyance of someone else having my data. SVN or rsync would make it very easy to sync this to my laptop or other machines.

  9. Ike Ahnoklast

    Has it occurred to you that when you write an article like this one (that isn’t full of content-free fluff) your readers might want to save the information it presents for later reference? As one such reader I typically keep a crib sheet with useful examples that I’ve cut’n'pasted from various sources. But here you are, perversely using PNG images in an article about an inherently textual command line tool, thereby making it impossible for us to preserve the info in question…

  10. John Smith

    @Ike

    You one ungrateful person. Instead of thanking the author for his time and effort, you bitch about him not going out of his way to post the way *you* want just because you are too lazy to type instead of just copy/paste.

    It is people like you that make us bloggers just want to stop sharing our knowledge and discoveries with the rest.

    If you want to save the information, learn how to save this article and others using Evernote or similar services or print to PDF.

  11. Dozer

    Really, Ike? There’s a text based entry posted above every visual example for each command line example given. The images under each command are an excellent visual representation of expected terminal output, as well as great pictorial references to system settings for those who may not be familiar with those features. That’s not a very tough format to understand. It’s literally 60 seconds of select all, copy all, and paste into your favorite word processor, followed by simply removing the images that offend you before saving it to file – If you really need to do that. I mean, come on. You’re chastising the author of this article because you’re inconvenienced by the extra effort it takes you to copy, paste and save the authors content for your own use. And yet it’s the use of PNG’s that you consider perverse… Focus, son. Focus.

  12. John Smith

    @Ike

    Instead of thanking the author for his time and effort, you complain about him not going out of his way to post the way *you* want just because you don’t want to type and instead you want to just copy/paste.

    Also, you missed the fact that each screenshot had a the text command/settings also included.

  13. on4aa

    @Ike
    For clutter-free archiving you could print this page to a PDF,
    or use the following Firefox extension:
    https://addons.mozilla.org/en-US/firefox/addon/unmht/?src=search

  14. Irish_IT

    @Ike
    Well done my troll friend…….Well done.

  15. Chris Hoffman

    @John Smith, Dozer

    Thanks, guys. Your comments made me smile.

  16. Alan

    I have yet to use remote directory mounting, but I plan to implement that soon. One thing I love about ssh is being able to easily port a full desktop: http://freenx.berlios.de/

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!