Saturday, August 13, 2011

HOWTO: Easily Share Files between Linux Machines using sFTP

Sharing files between two different computers on a network is something that I feel is often harder than it should be. Maybe it is just my bad luck or some poor configuration settings on the various networks I connect to, but Samba shares seem to almost never work for me. In the past year I've taken to using sFTP to transfer files back and forth between my various devices. sFTP is nice because it works over the internet and with any Unix devices that support ssh (including the N900)

For the purposes of this tutorial I am going to refer to the machine we are connecting from as "Machine A" and the machine we are connecting to as "Machine B". I am assuming the two machines are both connected to the same local network.

Getting Started -
To get started you will need to install the OpenSSH server package on Machine B. On Debian based systems (including Bodhi, Linux Mint, and Ubuntu) you can install this package by running the following in terminal:

sudo apt-get install openssh-server

On Machine A you will need to install a program for accessing Machine B. My program of choice is Filezilla, however you can use any program that supports the sftp protocol. If Machine A is Debian based you can install Filezilla with the command:

sudo apt-get install filezilla

Finding Your IP Address -
Next, you will need the IP address of Machine B so you can connect to it. If you are using the Gnome network manager (nm-applet) you can right click on the applet and select "connection information". The IP address is listed as the first line under IPv4:

You can also find your IP address via the command line on Machine B with the following command:

sudo ifconfig | grep "inet addr"

Connecting the Machines:

Finally, go ahead and load up Filezilla on Machine A. Selecting File - Site Manager. In the window that appears select "New Site" and enter the name of the system you are connecting to.

Then, where it says "Host:" enter the exact IP address we found in the step above. In the box where it says protocol click on the drop down and select "SFTP". Under "Logon Type:" you want it to say "Normal". "User:" is the exact, case sensitive, name you use to log into Machine B with and "Password:" is that user's password.

Finally, just tap the "Connect" button at the bottom of the site manager and you should be good to go. You can then simply drag and drop files between the two systems using the two pane panel Filezilla provides.

Have any questions or if any issues arise feel free to drop a comment below and I'll do my best to help you along.

~Jeff Hoogland


  1. Thanks Jeff. Just test it, works like charm. Very helpful. Samba has been failing lately and I'm glad to know this.

  2. That was easy. Thanks.

    Would you set the speed limit so that you would still have access to the web? If so, what would be a good speed to limit it to?

  3. Great article Jeff,

    I was having problems with SAMBA and was looking for an alternative, thanks.

  4. sftp is good stuff and there are lots of good programs that use it. OpenSSH tools provide free software users privacy and security that's second to none. Samba is a good project for talking to Windows, but you should not be using Windows.

    Konqueror has had sftp as an io slave for a long time. This makes other file systems look like local file systems, so you don't have to do as much dragging and dropping. If you want to drag and drop, just right click the notification area and select one of the "split plane" options to see that useful old trick that most file browsers discarded a decade ago. Konqueror also has a smb:// slave that talks to Windows systems, so you can glue all of your computers together through one free software box. Konqueror still runs well under nice Window managers like Enlightenment.

    Grsync is a front end to rsync, which uses OpenSSH tools to sync file systems. It works excellently as a local copy and remote sync using "user@host/path/" conventions.

    People should be careful with non free software, however, and never trust it. Transfers should be initiated from the free system using throw away passwords. Windows in particular has at least a 50% compromise rate and Microsoft themselves routinely keylogs users. If this makes things difficult, it's because Windows is difficult and should be avoided.

    A better solution is to run Windows in an VM like Virtual Box and only for a few legacy programs required by work. By reducing your dependency on legacy software, you reduce your need for garbage like Windows networking which will always sabotage free software. Virtual Machines can be accessed with virtual boot disks that run reasonable communications software to get information on and off them. People report being able to mount vdi files directly but I have not tried that.

  5. what if machine B is behind a broadband router?

  6. Someone asks, "what if machine B is behind a broadband router?"

    Your "broadband router" should be a gnu/linux box with OpenSSH. Besides getting a security advantage from having up to date software, you get storage, web service and a way to tunnel back into your home network. Everyone should have a two nic box.

  7. sFTP is great and it's good to see it promoted here. Those who plan to use it over the internet (rather than in a closed home network) might however want to add a bit more security.

    At the least, you would want to change the port on which you listen to something other than the standard 22 (which is a prime target for scripted attacks) and also set up a separate user account which does not have shell access and is chrooted to its home directory (for a easy-to-follow tutorial on this see )

  8. Very helpful - helping me to transfer assorted files between 2 home Debian computers.

  9. Hope I can try this on opensuse virtual machines Thanks

  10. I knew nautilus supports sftp so I was wondering about PcManFm. Turns out it does too, but requires you install sshfs first. After installing this open pcmanfm and enter the sftp address in the address bar, for your example: sftp://jeff@ You will prompted for the password and after entering it, you can browse the remote location in PcManFm the same as you browse your local hard drive.

  11. Great tutorial. Thanks a lot !

  12. If i am to share files between two debian based machine but over different network ( not on a home network ) would this method be helpful?

    1. yes, but see my earlier post re. securtity. You might also want to consider using webdav, or some sort of self-hosted cloud service such as owncloud or seafile.