image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
Thread Tools
  #1  
Old August 11th, 2004, 05:58 AM
Registered User
 
Join Date: Sep 2003
Posts: 374
Thanks: 0
Thanked 0 Times in 0 Posts
freaky is on a distinguished road
Best way to transfer a file using ssh?

Can somebody tell me what the best way to transfer a file from one UNIX server to another is that's easy to set do. I would prefer it to only be one line if possible. I looked into doing scp but it looks too complicated to have to generate/distribute the keys.
__________________
Mac Pro [2 GHz Quad Xeon, 3 GB RAM, 3 x 250 GB drives]
MacBook [2 GHz Intel Core 2 Duo, 2 GB RAM, 80 GB drive]
Reply With Quote
  #2  
Old August 11th, 2004, 06:10 AM
NSCoder
 
Join Date: Oct 2002
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
anarchie is on a distinguished road
It's not complicated to generate and distribute a key. You would use key-pair authentication to avoid entering your password for each copy, so you could use scp in scripts. You only need to generate a key once, and only transfer it once to each server you need authorization on. Here's the lowdown:

ssh-keygen -t dsa

This generates a DSA key and by default stores the keys in ~/.ssh/id_dsa and ~/.ssh/id_dsa.pub

cat ~/.ssh/id_dsa.pub | ssh someotherhost "mkdir ~/.ssh; cat > ~/.ssh/authorized_keys"

This transfers your public key to someotherhost. Afterwards, you can use 'ssh someotherhost' without entering your password, or you can use scp to copy files like so:

scp somefile someotherhost:~/somedirectory/somefile

And in reverse as well:

scp someotherhost:~/myfile mylocalfile
Reply With Quote
  #3  
Old August 11th, 2004, 11:03 AM
cfleck's Avatar
tired
 
Join Date: Nov 2002
Location: Indianapolis
Posts: 825
Thanks: 0
Thanked 0 Times in 0 Posts
cfleck will become famous soon enough
i've used scp for about 2 years now and i've never even had to do the keygen thing. i ssh in all the time though. besides, as far as i'm aware its the only way to do it in one line.
Reply With Quote
  #4  
Old August 11th, 2004, 12:19 PM
Registered User
 
Join Date: Sep 2003
Posts: 374
Thanks: 0
Thanked 0 Times in 0 Posts
freaky is on a distinguished road
Thanks for the replies. So if I have another site with a different login and password do I need to create a new key each time and name it something like ~/.ssh/id_dsa_site2 and ~/.ssh/id_dsa_site2.pub? After doing this if I want to log into the server via ssh do I need to go ssh user@domain.com or should I be able to just go ssh domain.com?
__________________
Mac Pro [2 GHz Quad Xeon, 3 GB RAM, 3 x 250 GB drives]
MacBook [2 GHz Intel Core 2 Duo, 2 GB RAM, 80 GB drive]
Reply With Quote
  #5  
Old August 11th, 2004, 12:30 PM
cfleck's Avatar
tired
 
Join Date: Nov 2002
Location: Indianapolis
Posts: 825
Thanks: 0
Thanked 0 Times in 0 Posts
cfleck will become famous soon enough
if your username on the machine you are using is the same as the machine you are logging in to then 'ssh domain.com' is fine, otherwise you need to use 'ssh user@domain.com'

for scp, the same rule applies.
different user name, copy from server to local - 'scp user@domain.com:filename newfilename'
same user name, copy from server to local - 'scp domain.com:filename newfilename'

if you are copying to the server just switch args 2 and 3. that is...
scp localfile domain.com:newfile

basically, the stuff after the : is the path & filename on the foreign machine.

i wouldn't worry about the keygen stuff at first. try it without and see if it works.
Reply With Quote
  #6  
Old August 11th, 2004, 08:31 PM
NSCoder
 
Join Date: Oct 2002
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
anarchie is on a distinguished road
You only have to generate a key once on your machine. If you WANT to, you can use multiple keys, but you'll need to use the -i option to tell ssh/scp which key to use. That can get real tedious.

cfleck: As I pointed out, you would use keypair authentication so that you don't need to enter your password, which makes automation easy. If you can use ssh or scp without entering passwords, chances are that the identity and authorized_keys files have already been set up for you. Keypair authentication is not necessary at all, but I interpreted "on one line" as not needing to enter the password on another line.
Reply With Quote
  #7  
Old August 11th, 2004, 11:13 PM
cfleck's Avatar
tired
 
Join Date: Nov 2002
Location: Indianapolis
Posts: 825
Thanks: 0
Thanked 0 Times in 0 Posts
cfleck will become famous soon enough
aah, i see, i see. i was wondering why the keygen thing was no necessary, and it never really clicked. slow wednesday.
Reply With Quote
  #8  
Old August 12th, 2004, 01:07 AM
Registered User
 
Join Date: Sep 2001
Location: Tokyo, Japan
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
legacyb4 is on a distinguished road
Assuming your SSH server is configured to run it, SFTP also works like a standard FTP program (put, get, etc.) but runs through an encrypted channel.
__________________
Macbook (Black) C2D/120GB/2GB | G5/1.6 250GBx2/1.25GB
Free Mobile Phone Ringtone, Application, & Screensaver Uploader
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 10:06 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.