Clan x86

Technical (Development, Security, etc.) => Unix / Linux Discussion => Topic started by: Joe on April 13, 2006, 06:35:31 pm

Title: Ugh, help with SCP
Post by: Joe on April 13, 2006, 06:35:31 pm
Ok, I have no clue how to do this. I want to copy a zip file from ~/Desktop/JBot/src.zip to joe@darkside:~/public_html/JBot/src.zip nightly, but I have no clue how to do this.

Also, I have to go through Pie to get to darkside, because apparently iago's port forwarding died (again).

Could one of you magicians spoon-feed the command do to this? =)
Title: Re: Ugh, help with SCP
Post by: iago on April 13, 2006, 07:06:56 pm
There should be nothing wrong with the port forwarding.  The computer hasn't restarted and I haven't touched that service, so if it's not working then ssh would have had to crash or something. 

Anyway, scp is very simple.  It is in the form of:

scp <src> <dest>

Where src and dest are file paths.  A file path can be one of two things:
a) A direct or relative path to the file, like "/etc/passwd" or "./file.txt"
b) Made up of two parts, separated by a colon, "server:path".  In that case, the server is the server that is running ssh and path is the path of the file.

Note that b) can be used for the source or destination or both.  You can also put nothing for the path, just "server:" which copies it to the default folder. 

This would copy /etc/passwd on 192.168.1.2 to the root folder on 192.168.1.3:
scp 192.168.1.2:/etc/passwd 192.168.1.3:/

This would copy /etc/passwd on the current system to 192.168.1.3:
scp /etc/passwd 192.168.1.3:/

This would copy /etc/passwd on 192.168.1.2 to the root folder on the current computer:
scp 192.168.1.2:/etc/passwd /
Title: Re: Ugh, help with SCP
Post by: Joe on April 13, 2006, 08:28:01 pm
scp ~/Desktop/JBot/src.zip www.javaop.com:~/public_html/JBot/src.zip

How do I send my password to darkside, and how do I use a port?
Title: Re: Ugh, help with SCP
Post by: Ergot on April 13, 2006, 08:47:59 pm
It prompts for a password.

scp --help
man scp
Title: Re: Ugh, help with SCP
Post by: Joe on April 13, 2006, 09:07:53 pm
Well then that's a bad thing. This is for a crontab file, I need to be able to run scp without being there. =/
Title: Re: Ugh, help with SCP
Post by: Newby on April 13, 2006, 11:30:36 pm
Joe: RTFM

Quote from: man scp (on FreeBSD 6.0)
SCP(1)                  FreeBSD General Commands Manual                 SCP(1)

NAME
     scp -- secure copy (remote file copy program)

SYNOPSIS
     scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
         [-l limit] [-o ssh_option] [-P port] [-S program]
         [[user@]host1:]file1 [...] [[user@]host2:]file2

...

     -B      Selects batch mode (prevents asking for passwords or
             passphrases).

Read the red.

According to that, you should be able to supply the password (in the form of a text file or a parameter) if you use -B. Figure it out!

I wish I did man scp earlier. Sending all that Grave Digger to iago would have been quicker with -C and -l 30. :)
Title: Re: Ugh, help with SCP
Post by: Joe on April 14, 2006, 02:39:53 am
Woo, got it. Thanks guys.

http://support.svi.nl/wiki/ScpBatchMode
Title: Re: Ugh, help with SCP
Post by: iago on April 14, 2006, 12:52:30 pm
Joe: RTFM

Quote from: man scp (on FreeBSD 6.0)
SCP(1)                  FreeBSD General Commands Manual                 SCP(1)

NAME
     scp -- secure copy (remote file copy program)

SYNOPSIS
     scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
         [-l limit] [-o ssh_option] [-P port] [-S program]
         [[user@]host1:]file1 [...] [[user@]host2:]file2

...

     -B      Selects batch mode (prevents asking for passwords or
             passphrases).

Read the red.

According to that, you should be able to supply the password (in the form of a text file or a parameter) if you use -B. Figure it out!

I wish I did man scp earlier. Sending all that Grave Digger to iago would have been quicker with -C and -l 30. :)

Nah, I've sent .mp3 files with -C before.  It sends slower because it takes more processing time but doesn't shrink it very much. 

And you should NOT supply the password in the plaintext file.  You should set up ssh with public/private keys. 

- On your computer, run "ssh-keygen -t rsa".  Go through the steps, and give it a blank password. 
- Open ~/.ssh/whatever.pub.  That's your public key
- Copy your entire public key
- Create a new file on the server, ~/.ssh/authorized_keys
- Put your public key in authorized_keys

Here's a simple way:
Quote
ron@slayer:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ron/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ron/.ssh/id_rsa.
Your public key has been saved in /home/ron/.ssh/id_rsa.pub.
The key fingerprint is:
2b:f3:68:0b:79:81:f1:9d:be:c9:31:b5:d8:1c:42:b3 ron@slayer
ron@slayer:~$ scp .ssh/id_rsa.pub iago@darkside:.ssh/authorized_keys
iago@darkside's password:
id_rsa.pub                                    100%  220     0.2KB/s   00:00   
ron@slayer:~$ ssh iago@darkside
iago@darkside:~$



Notice how I didn't need a password the second time?  I cheated, though, by just renaming "id_rsa.pub" to authorized_keys.  If I ever wanted to add another key, I'd have to add the public key manually. 

Get it?
Title: Re: Ugh, help with SCP
Post by: Joe on April 14, 2006, 03:18:30 pm
Yeah iago, that's exactly what I did, the whole key thing. It's what the link said to do, so eh.