Accessing Remote Files Easily and Securely
The secure shell, ssh, and its companion, scp, are tools that I use more or less on a daily basis. Being able to move files between machines without having to setup SAMBA or NFS is very handy when working with multiple systems. All that you need is to enable the secure shell daemon - sshd.
Before we go into the details of the sshfs, let's run through a quick re-cap of ssh. The secure shell daemon runs on port 22 by default. It makes it possible to run an encrypted shell session. With the -Y flag, you can even run X11-forwarding, allowing you to run X11, i.e. graphical, programs on the remote machine and displaying the windows on the terminal that you are sitting at.
You can configure sshd through the /etc/ssh/sshd_config file (that is the location on my Kubuntu machine). Here, you can disable root access, older protocols, X11 forwarding, etc. The notion is that the more limits you put on the remote access, the more secure your system is from potential attacks. You might also want to tune your hosts.allow and hosts.deny files if you plan to expose sshd to the Internet. There are many guides on hardening servers and ssh, so I will not go into details.
To get things up and running, what you need to do is to install sshd. In Ubuntu, that means the openssh-server package. For external access, you also need to enable port forwarding of port 22 in your router/firewall and find your external IP. Now, you should be able to log onto your machine using your normal user credentials.
$ ssh user@192.168.1.100 user@192.168.1.200's password:
Having entered the password, you should now have full access to the remote system.
The handy scp command, secure copy, works in much the same way. To copy the file test.txt to user's remote home directory, simply enter:
$ scp test.txt user@192.168.1.100:
As before, you will be prompted for a password. You can copy the other way around as well. The command below demonstrates how to copy a file with an absolute path, i.e. not in the home directory of user, to your local machine.
$ scp user@192.168.1.100:/var/log/messages remote-messages
These two commands means that you can browse the file system, and freely copy files between machines. What sshfs does is that it exposes this functionality as a file system that you can mount. Before we look into how, let's have a quick look at sshfs.
The sshfs is implemented using FUSE, and relies on the sftp part of ssh to access the remote computer. As a remote file access protocol, sshfs is not very good. For instance, multiple users writing to the same file at once can create havoc. The benefits are the inherit security and that it is easy to setup.
So, how to use it. Let's look at a very short demonstration.
$ sshfs user@192.168.1.100: remote-home $ ls remote-home Desktop Documents Downloads Music $ fusermount -u remote-home
The initial sshfs command mounts the user's home directory to remote-home. You can specify another path after the colon to mount any other part of the remote file system. Access is only restricted by user's access rights.
Using ls, or any other ordinary command, will work as if the remote home directory was mounted locally. All tools work. For instance, you can log onto your remote machine and build software using your locally installed setup of build tools.
To unmount the filesystem, the fusermount command from the FUSE utilities package is used.
To summarize, sshfs an easy setup remote file access tool. It needs to be used with care if multiple users are involved. It makes it dead easy to temporarily access remote file systems, as well as mounting file systems from virtual machines for easier access and monitoring, as well as for remote installation, compilation and debugging. All-in-all, one of the tools I always keep handy in my toolbox.
Johan Thelin is a consultant working with Qt, embedded and free
software. On-line, he is known as e8johan.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
- Keeping track of IP address
1 hour 48 min ago - Roll your own dynamic dns
7 hours 1 min ago - Please correct the URL for Salt Stack's web site
10 hours 13 min ago - Android is Linux -- why no better inter-operation
12 hours 28 min ago - Connecting Android device to desktop Linux via USB
12 hours 56 min ago - Find new cell phone and tablet pc
13 hours 55 min ago - Epistle
15 hours 23 min ago - Automatically updating Guest Additions
16 hours 32 min ago - I like your topic on android
17 hours 18 min ago - This is the easiest tutorial
23 hours 54 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
But you need to be root...
But you need to be root... in order to mount a file system on your local machine...
I am afraid your $ sign in front of your commands is a little bit misleading, or at least use a "sudo" before commands.
Anyway, I didn't know sshfs and I have to say it is pretty handy, thanks for sharing!
Ciao.
I'm not sure that the root /
I'm not sure that the root / sudo requirement holds true in all setups. I'm pretty sure that can do sshfs mounts in my Kubuntu installation as my ordinary user (on vacation now, so I cannot check to make 100% sure).
Johan Thelin is a consultant working with Qt, embedded and free
software. On-line, he is known as e8johan.
Missing words?
I think the line "These two commands means that you can browse the file system freely copy files between machines" is missing something, maybe a comma or "and"?
Nice article, thanks!
Thanks! I'll fix it.
Thanks! I'll fix it.
Johan Thelin is a consultant working with Qt, embedded and free
software. On-line, he is known as e8johan.
Spaces in file names
scp and sshfs are truly sweet quick and dirty tools.
I've been using sshfs for years for mounting my remote folder filled with music so the local music player on the laptop connect not to the unsynced local storage but directly to the source (, yo!).
I just haven't figured out how to make scp accept spaces in file names. On Linux filesystems i usually don't use spaces in file names but copying anything out of a Wintendo parition is bound to have a space in the filepath...
Tripple escape
What you need to do is to escape the space with a backslash, but you need to do it twice. Once for the local machine and once for the remote. To add the second backslash, you need to escape it as well. This means that you will have to use tripple backslashes for each space, e.g. 192.168.1.100:monty\\\ python.
Johan Thelin is a consultant working with Qt, embedded and free
software. On-line, he is known as e8johan.
try this\ is_windows\
try this\ is_windows\ file_with\ spaces
Typo in Story
Shouldn't line in story:
$ user@192.168.1.100:/var/log/messages remote-messages
Read as:
$ scp user@192.168.1.100:/var/log/messages remote-messages
It should. Thank you! I'll
It should. Thank you! I'll have it fixed.
Johan Thelin is a consultant working with Qt, embedded and free
software. On-line, he is known as e8johan.