Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am running Ubuntu 9.10 desktop on my home machine. I need to upload files from my local machine, to my web server, on a periodic basis. My server is running Ubuntu Server LTS.

I want my server to be secure, and only run the LAMP stack and possibly, an email server. I do not (ideally) want to have FTP or anything that can allow (more) knowledgeable hackers to be able to hack into my server.

Can anyone recommend how I may send files from my local machine to the server?

This may seem an easy/trivial question, but I am relatively new to Linux - and I got my previous Windows server machine serious hacked in the past, hence the move to Linux, and thats why I am so security conscious.

[Edit]

There seems to be quite a lot of ways of doing this (judging from the answers I have received so far) - yet there seems to be no clear winner. therefore, I am adding some more information, in the hope that a clear winner (in terms of best practices) will emerge.

  1. I would like to automate this - i.e. run from a shell script as a cron job.
  2. I am concerned about security, and so, I dont want to have passwords in plain text in the scripts or to send passwords unencrypted etc
  3. Both the client and (remote) server are Debian based, so hopefully, file permissions will be preserved in the copy.

    i. If this is not possible, who will be the default owner of the copied files? The uploaded files will be read by another script (on the server). What should the relationship (in terms of file permissions) be, between the uploading script and the processing script?

share|improve this question

4 Answers 4

up vote 1 down vote accepted

rsync is a handy way to transfer files between servers. Works over SSH out of the box (and supports key-based passwordless SSH connections).

You can copy from local to remote or fetch from remote to local, etc. For example:

# copy files to another server
rsync -avz /mnt/myfiles/ myuser@mydomain.com:/srv/myfiles

On the remote server it's good to use a non-root account, and set up an authorized_keys entry so that you don't need to put in your password. SSHing directly into root on another server is not a good idea - if you need root privs on the remote server, do the rsync from that end instead. If you think you need root privs on both servers, you may not: look into rsync's --fake-super option.

I've looked at a number of HOWTOs online and a lot of them recommend frankly bad practices or are out of date (recommending authorized_keys2, rsa, etc). This one I recommend, it's good security-wise: http://troy.jdmz.net/rsync/index.html

share|improve this answer
    
how do I "set up an authorized_keys entry"?. Also, could you please clarify whether this setup is done on the (remote) server or the client (I'm guessing its the server, but I dont want to make any assumptions where security is concerned). Regarding file permissions, both OS's are Deian based so I assumed file permissions will be preserved (no?) –  user35402 May 12 '10 at 11:27
    
@morpheous, this page includes some info about setting up key based auth over SSH: troy.jdmz.net/rsync/index.html Given that both computers are Linux-based then it'll make it a bit easier. As for preserving permissions, you'll be fine. The -a part preserves those. It won't preserve owners/groups, which you probably don't want when going between servers unless it's a backup, in which case look into --fake-super option under rsync's documentation, but that is kinda complicated and requires xattrs on the destination filesystem. –  thomasrutter May 13 '10 at 4:07

Other, very convenient IMO, way is to mount your remote dir as local using sshfs and copy files as any other.

sshfs user@remotemachine:/remote/dir /local/dir  
cp /one/file /local/dir/.
share|improve this answer
    
I use this way very often. Especially that sshfs mounting can be added to /etc/fstab so it can be simplified just to cp :) –  Satanowski May 11 '10 at 12:55
    
What about security?. i.e. it looks to me (as a newbie), that anyone who knows the username 'user' will be able to copy files onto the machine (clearly, that cannot be the case). Additionally, I would like to automate this (i.e. run from a script), but I dont want to use plain text passwords –  user35402 May 12 '10 at 11:30

chances are you already connect to the server using ssh.. so use scp or sftp which uses ssh as the protocol

scp localfile user@domain.com:/path/to/place/localfile

It will prompt you for your password

If you want it to get easier and more secure.. look into logging in with ssh keys

EDIT

Here is the sftp.. works just like normal ftp once you are in

  sftp user@domain.com
  > cd /dir/dir2/dir3
  > put localfile 

I would use scp if you want to automate it.. so to create a sshkey

ssh-keygen -t dsa

If you want to automate it.. I recommend using no passpharse

Now you want to copy the key

ssh-copy-id user@domain.com

Then you can ssh in with no password as that user while using that key. you can also use the same scp account with no password.. but it will only work with that key for the user you created it with.

share|improve this answer
    
Mike: thanks for the quick response. I am very new to all of this (both Linux and Linux admin). I prefer the SFTP otion. Could you please give some more info on using SFTP (especially with regard to using the SSH keys - I suppose I will have to generate my own? [I dont know how). Also, I would like to run the commands in a shell script, so I need to be able to somehow automate this, ie. carry out the file transfer without being prompted for uname/pwd. –  user35402 May 11 '10 at 12:54

If you need a GUI rather than command line option, just use SFTP. FileZilla is a dead easy client to use and drag'n'drop, and of course SFTP does everything over an SSH connection.

Again, connect to a non-root account on the remote server - and you can set up passwordless login by adding an authorized_keys entry to the remote machine. You'll need Pageant (comes with PuTTY) to manage keys on Windows.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.