Linux-Noob Forums

Full Version: Easy question - How do I combine scp & ssh?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Hi. I'm a newbie and working on a shell script.

 

Trying to first get one small file from a web server -- wget [/url][url=http://test.com/myfile.xml]http://test.com/myfile.xml

 

Then I need to scp it to the db server. I've set up a single-purpose ssh keys and by running this can connect w/out entering password:

 

ssh -i ~/.ssh/whoisit MyHostName

 

 

My problems is this: when I run scp myfile.xml MyHostName:/dir1/dir2/myfile.xml, I get prompted for password.

If I run the ssh command above, I instantly connect to the db server and cannot scp, because I'm already on the remote machine.

 

So, my question is how do I utilize the ssh keys I've set up with scp. I just want to:

1) wget file

2) activate the ssh key, so I connect to the db server w/out entering password

3) copy the file to db servers /dir1/dir2

4) do some kind of a check if the file made it there allright

 

Thank you,


Quote:Hi. I'm a newbie and working on a shell script. 

Trying to first get one small file from a web server -- wget [/url]http://test.com/myfile.xml

 

Then I need to scp it to the db server. I've set up a single-purpose ssh keys and by running this can connect w/out entering password:

 

ssh -i ~/.ssh/whoisit MyHostName

 

 

My problems is this: when I run scp myfile.xml MyHostName:/dir1/dir2/myfile.xml, I get prompted for password.

If I run the ssh command above, I instantly connect to the db server and cannot scp, because I'm already on the remote machine.

 

So, my question is how do I utilize the ssh keys I've set up with scp. I just want to:

1) wget file

2) activate the ssh key, so I connect to the db server w/out entering password

3) copy the file to db servers /dir1/dir2

4) do some kind of a check if the file made it there allright

 

Thank you,
 

First off, you want to get Public/Private Key Authentication setup: http://kutzooi.co.uk/howto.php?005

Then you want to do this: [url=<___base_url___>/index.php?showtopic=2848][/url][url=<___base_url___>/index.php?showtopic=2848]https://www.linux-noob.com/forums/index.php?showtopic=2848 (just before it says edit your bashrc)

 

But when you are making/editing the ~/.ssh/config add an extra line into it:



Code:
Host some
  HostKeyAlias somelong.hostname.com
  HostName somelong.hostname.com
  IdentityFile /home/user/.ssh/whoisit
  User znx
  Port 12345




 

Now you should be able to just do: ssh some or scp file some:./filename or doing directories scp -r dir1/ some:./dir1

 

To do a check that it made it there ok you can send an ssh with ls like this: ssh some ls filename or you could do an md5 check with ssh some md5sum filename

 

Hope that helps