Easy and secure remote Linux/Unix file transfers with SCP

Sometimes you need to transfer files between Linux boxes, or between a Linux box and some other box, and setting up Samba or some other form of network file system may not be practical (maybe you only need to transfer a couple of files, or maybe it’s just a one-time thing) or possible (maybe there’s a firewall involved).
Well, you should already have SSH installed on your Linux boxes so you can remotely log in and administer them. On Debian, apt-get install ssh sshd. If you’re running distro based on Red Hat or UnitedLinux, you may have a little investigative work to do. (I’d help you, but I haven’t run anything but Debian for 2 or 3 years.)

The cool thing about SSH is that it not only does remote login, but it will also do remote file transfer. And unlike FTP, you don’t have to stumble around with a clumsy interface.

If you want to transfer files from a Windows box, just install PuTTY. I just downloaded the 240K PSCP.EXE file and copied it into my Windows directory. That way I don’t have to mess with paths, and it’s always available. Make sure you’re downloading the right version for your CPU. The Windows NT Alpha version won’t run on your Intel/AMD/VIA CPU. Incidentally, Putty.exe is a very good Telnet/SSH client and a must-have if you’re ever connecting remotely to Unix/Linux machines from Windows.

SSH includes a command called SCP. SCP works almost like the standard Unix CP command. All you to do access a remote file is append a username, followed by the @ sign, and the IP address of the remote server. SCP will then prompt you for a password.

Let’s say I want to move a file from my Linux workstation to my webserver:

scp logo.jpg root@192.168.1.2:/var/www/images

SCP will prompt me for my password. After I enter it, it’ll copy the file, including a nice progress bar and an ETA.

On a Windows machine with PuTTY installed, simply substitute the command pscp for scp.

I can copy the other way too:

scp root@192.168.1.2:/var/www/index.php .

This command will grab a file from my webserver and drop it in the current working directory.

To speed up the transfers, add the -C switch, which turns on compression.

SCP is more secure than any other means of file transfer, it’s probably easier (since you already need SSH anyway), and since it’ll do data compression, it’s probably faster too.

6 thoughts on “Easy and secure remote Linux/Unix file transfers with SCP

  • December 3, 2003 at 12:22 am
    Permalink

    Good tip. As a Unix admin and Linux user who has to also work with Windows boxes I find scp and Putty to be very handy.

    Also, for those who want an ftp-like interface, but still secure like scp, sftp is good. Since sftp uses ssh for transport, it is secure, unlike ftp. I’m not sure about all ssh implementations, but it seems to be generally available on systems that have ssh (at least openssh) installed.

    As for Debian and apt, they are great. What is not so well known is that apt has been ported to work with rpm based distributions like Red Hat. There are also other similar tools now, like yum.

    Red Hat (or Fedora) users can check out http://apt.freshrpms.net/ if interested.

  • December 3, 2003 at 12:24 pm
    Permalink

    Another often-overlooked SSH tip: In addition to getting a shell on a remote machine, you can execute a command on a remote machine:

    ssh [options] user@remotemachine [command]

    will execute command as user on remotemachine.

    You can in fact pipe data to a remote command and get back the output, which is also fun. A simple, yet useless, example would be:

    cat file | ssh user@remotemachine grep “blog”

    would use grep on remotemachine to grab lines containing “blog” in file on local box.

  • December 3, 2003 at 1:06 pm
    Permalink

    Thanks, Dave!

    …and thank you also, Steve; that looks like something to try.

  • December 3, 2003 at 9:48 pm
    Permalink

    One use I like is to use Putty from work to access a linux machine at home; one there, run vncviewer in work and connect over a ssh tunnel to the machine at home.

    From there, if I need access to my XP machine, it’s just a question of a quick rdesktop and Bob’s your uncle!

  • December 5, 2003 at 8:51 pm
    Permalink

    I’ve been using the commercial ssh (ssh.com) for a few years under their personal/educational license on my winder$ boxen. It’s an easy install and provides a nice GUI for the sftp protocoal, which my students approve of.

Comments are closed.

%d bloggers like this:
WordPress Appliance - Powered by TurnKey Linux