Transferring files with OpenSSH

Posted by Anonymous on Mon 11 Oct 2004 at 12:49

Tags: ,

OpenSSH is a well known program which allows you to login to a host remotely, and run commands etc. It also comes with a simple file transfer system which can be used to transfer files securely.

scp is the command to use. You can either transfer files to the remote machine from your local one, or vice versa.

Usage is as simple as:

scp file-to-send user@host:/path/to/place/file

For example to copy the password file from your local machine (bennevis to a remote server called 'earth' you could use:

steve@bennevis:~$ scp /etc/passwd steve@earth:
steve@earth's password:
passwd               100% |*****************************|   918       00:00

As no destination directory was specified the file will be transferred to your home directory upon the remote machine.

If you wish to transfer a lot of files you can copy a directory recurisvely, with the -r flag.


When it comes to sending files to and from you Unix machine from a Windows desktop you can use the excellent open source program WinSCP which presents a drag and drop interface to remote file systems - allowing you to drag and drop files with ease.

With OpenSSh installed you have no reason to be running insecure systems such as FTP to copy files to and from your Unix servers.

 

 


Posted by yaarg (127.0.xx.xx) on Fri 15 Oct 2004 at 08:03
[ View Weblogs ]

Beware copying many files with scp (like maybe backing up a filesystem) it doesn't seem to maintain permissions too well.. :/ (Tardis recently learnt the hard way! )

[ Parent | Reply to this comment ]

Posted by Steve (127.0.xx.xx) on Fri 15 Oct 2004 at 10:52
[ View Steve's Scratchpad | View Weblogs ]

scp will preserve permissions if you use '-p' when copying...

-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (127.0.xx.xx) on Mon 18 Oct 2004 at 00:46

will that work if something is setgid? :/

[ Parent | Reply to this comment ]

Posted by Steve (127.0.xx.xx) on Mon 18 Oct 2004 at 08:30
[ View Steve's Scratchpad | View Weblogs ]

Looks like it:

root@earth:~# touch t
root@earth:~# chown root:root t
root@earth:~# chmod 2755 t
root@earth:~# ls -ltr
total 4
drwx------    2 root     root         4096 Jun 29 14:40 Mail
-rwxr-sr-x    1 root     root            0 Oct 18 09:30 t
root@earth:~# scp -p t localhost:/tmp
root@localhost's password:
t                    100% |*****************************|     0       00:00
root@earth:~# ls -l /tmp/t
-rwxr-sr-x    1 root     root            0 Oct 18 09:30 /tmp/t

-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (127.0.xx.xx) on Mon 18 Oct 2004 at 09:40

Ah good. Thanks for testing.

[ Parent | Reply to this comment ]

Posted by fsateler (200.83.xx.xx) on Thu 16 Jun 2005 at 00:19
[ View Weblogs ]
You can also use sftp... works exactly like ftp, but through ssh.

Felipe Sateler

[ Parent | Reply to this comment ]

Posted by Anonymous (64.139.xx.xx) on Fri 15 Jul 2011 at 10:25
i don't want to retain any permissions at all (unless i specify), how do i do that?

[ Parent | Reply to this comment ]

Posted by Anonymous (86.122.xx.xx) on Sat 23 Jun 2012 at 21:11
if you do not want to keep permissions ... why do you care? just transfer files and you`r done

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 492 votes ~ 5 comments )