How to Install and Use SSH (Secure Shell) in Ubuntu

- select the contributor at the end of the page -
Many of us now regularly use more than one computer – at home, the office, or even customer sites. Consider this scenario: you're happily typing along on your work computer only to realize you need to access a file on your home computer. How can you, sitting at your desk across town, obtain the file without having to race home? Answer: remote access.

SSH or secure shell, is a protocol that allows you to securely access one computer from another. Not only can you transfer files, but if you are concerned about public wi-fi security, SSH can help. Using the command line or a graphical interface, you can bypass potentially prying eyes and create a secure virtual private network (VPN) that tunnels your Internet traffic through your home computer's connection.

To use SSH, you'll need to install the SSH client on the computer you connect from, and an SSH server on the computer you connect to. Under Linux, the most popular software provider is the OpenSSH project.

How to Install and Use SSH (Secure Shell) in Ubuntu

How to Install OpenSSH

OpenSSH is of course, an open source product and contains both the client and server components.

The client software is part of the default Ubuntu installation. If you want to be able to accept SSH connections as well as request them, you'll need the server software as well. Install it with this command:

sudo apt-get install openssh-server

How to Use SSH to Login to a Remote Computer

In order to access a remote computer, you'll need to have an account on that machine. You may want to set up a guest account. Navigate to System > Administration > Users and Groups. Create a user (or group of users) and assign the permissions as needed.

When OpenSSH is installed and your user created, login to the remote computer with this command:

ssh username@hostname

Username is the name of the user you created and hostname is the name of the computer (or host) or its IP address. So if you had a computer at home with an account called janedoe, from the command line you would type:

ssh [email protected] or ssh janedoe@myhompc

Copying Files using SSH

Now that you've made the connection to your remote computer, you'll probably want to transfer or copy some files. The secure copy command (scp) allows you to securely copy files to and from the remote box. The syntax is as follows:

scp filename.extension remoteuser@remotebox:/directory

Copying Directories using SSH

To copy an entire directory (and all of its contents) from the local machine to the remote server, use the recursive -r switch:

scp -r /local/directory remoteuser@remotebox:/remote/directory

/local/directory is the path to the local directory you want copied, and /remote/directory is the remote directory where you want the directory to be copied.

To reverse this and copy from the remote box to local, just switch things up accordingly:

scp -r remoteuser@remotebox:/remote/directory /local/directory

What about Windows?

If you need to remotely connect to your Ubuntu box from a Windows machine, you'll need both PuTTY and TightVNC viewer. Follow the instructions here.

Final Thoughts

For more detailed information behind these communications protocols, visit the Ubuntu Wiki for your version. Also remember to keep permissions in mind if you choose to provide remote access to other users. Restrict access to only those files or directories that are absolutely required. I hope you've enjoyed our look into remote access under Ubuntu.

 

Ready to test your skills in Ubuntu? See how they stack up with this assessment from Smarterer. Start this Ubuntu test now

Get our content first. In your inbox.

Loading form...

If this message remains, it may be due to cookies being disabled or to an ad blocker.

Contributor

Veronica Henry

Veronica Henry is a writer, web developer and tech guru. Her 20 year IT career came to an end when her inner writer and entrepreneur inexplicably besieged her to give it all up. She is a self-proclaimed girl-geek and linux convert, who has held MCSE, GSEC and PMP certifications. In her dreams, she is a international best-selling sci-fi and fantasy author, but in the meantime, she now spends her days writing, managing her websites and wrecking havoc on her Ubuntu laptop.