LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2014, 05:54 PM   #1
bowserface
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Rep: Reputation: Disabled
Trouble SCP'ing a file from remote server to local machine, running out of ideas!


Hello All!

I have a server running on Amazon EC2, and I have generated a file on that remote server (via an SSH connection) that I'd like to move to my local machine (FWIW this file is a OpenVPN key file, i.e. 'openvpn-key.txt').

I'm been trying a number of different variations of the SCP command and none seem to work.

Code:
scp -i openvpn-key.txt ubuntu@XX.XX.XX.XX:/etc/openvpn /Users/XXXXXX/Desktop
gives me the following error:

Code:
Warning: Identity file openvpn-key.txt not accessible: No such file or directory.
Permission denied (publickey).
I've modified the permissions on both the specified file and the directory (on the remote machine) to be 777 for both, but this doesn't seem to help.

Running the same SCP command as root:

Code:
sudo scp -i openvpn-key.txt root@xx.xx.xx.xx:/etc/openvpn /Users/xxxxx/Desktop
gives me the same error. I have no doubt I am missing something on the command syntax (or something equally minor)...any help would be greatly appreciated. Thanks!
 
Old 02-17-2014, 05:58 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
not sure the location of that file but this is the generic form of the scp command:
Code:
scp user1@host1.net:/path/to/filename1 user2@host2.net:/path/to/filename2
if this is manual you mite want to use sftp since it has human readable prompts.

Last edited by schneidz; 02-17-2014 at 06:01 PM.
 
Old 02-17-2014, 06:08 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,568

Rep: Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865
The -i option is to indicate the location/name for the ssh private key if different then the default. if you want to copy a file then the command is as stated above. If I understand what you are copying in your case /path/to/filename1 would be /etc/openvpn/openvpn-key.txt

Last edited by michaelk; 02-17-2014 at 06:12 PM.
 
Old 02-17-2014, 06:25 PM   #4
bowserface
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
the current directory on the local machine (i.e. where I am running the command from) is where the .pem file for the remote server sits...so my thought was that the -i would capture that as long as I was in the right directory.

I believe you're right, re: the path for filename 1.

This seems like (or is) a stupid question, but this

Code:
user2@host2.net:/path/to/filename2
has me confused, as user2@host2 is me at my local machine, and the filename shouldn't change, hence copy. Right?
 
Old 02-17-2014, 06:27 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
if no user or host name or directory path is given on the command line, the scp command will assume the current user, localhost and pwd.
 
Old 02-17-2014, 06:34 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,568

Rep: Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865Reputation: 5865
Correct, since the destination is your local PC then
user2@host2.net:/path/to/filename2 = /Users/XXXXXX/Desktop
 
Old 02-17-2014, 06:40 PM   #7
bowserface
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Alright then, with this command:

Code:
sudo scp ubuntu@XX.XX.XX.XX:etc/openvpn/openvpn-key.txt
I'm getting an SCP syntax error:

Code:
usage: scp [-12346BCEpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
THoughts?
 
Old 02-17-2014, 06:44 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
not sure why you want to use sudo.

scp is like the cp command... you need to tell it where to copy it to ?

also, you probably want a '/' at the beginning of the path (e.g.: /etc/openvpn/openvpn-key.txt)

Last edited by schneidz; 02-17-2014 at 06:45 PM.
 
Old 02-17-2014, 06:54 PM   #9
bowserface
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Yeah, that '/' was an oversight. Anyway, here's the latest:

Code:
scp ubuntu@XX.XX.XX.X:/etc/openvpn/openvpn-key.txt /Users/XXXXX/Desktop
But that gets me back to the original error I was receiving:

Code:
Permission denied (publickey)
 
Old 02-17-2014, 07:00 PM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i am stumped... i see this:
http://stackoverflow.com/questions/1...n-ec2-instance

i guess you can try it with sudo again ?
 
Old 02-17-2014, 07:15 PM   #11
bowserface
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Stumped is an understatement! I added sudo back...sadly same error. Of course all sudo does is add those permissions to the local user on the local machine. This error is almost certainly based on something server side.

The link you sent is a good one, one I found as well. To address those points. I use the same .pem file to successfully SSH to the instance, so we're good on that one. And for the user, it's an Ubuntu instance, so I'm using that username as well.

FWIW I also tried Filezilla. I can connect and browse the remote server. When I try to download the same file though, it gives me an error

Error: local: unable to open /openvpn-key.txt
Error: File transfer failed

Last edited by bowserface; 02-17-2014 at 07:20 PM.
 
Old 02-17-2014, 07:17 PM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
seems like amazon is doing something non-standard to block ssh access... have you contacted their teck-support ?
 
Old 02-17-2014, 07:29 PM   #13
bowserface
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
I haven't, their forum is probably next if this really is a Amazon EC2 thing vice just my Linux newb'ness.

They might be doing something with SSH, but I have SSH opened on server (via the Amazon config mechanism). I can also SSH to it without any issues using standard commands and the pen file.
 
Old 02-18-2014, 08:05 AM   #14
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by bowserface View Post
I haven't, their forum is probably next if this really is a Amazon EC2 thing vice just my Linux newb'ness.

They might be doing something with SSH, but I have SSH opened on server (via the Amazon config mechanism). I can also SSH to it without any issues using standard commands and the pen file.
syntax error(s)...I believe, so try
Code:
scp -i /path/to/openvpn-key.txt ubuntu@XX.XX.XX.XX:/etc/openvpn /Users/XXXXXX/Desktop/
assuming contents of openvpn-key.txt.pub are in /home/ubuntu/.ssh/authorized_keys on the Amazon host and that authorized_keys file is 600 and owned by ubuntu:ubuntu

is /etc/openvpn a file or directory?
 
Old 02-18-2014, 05:34 PM   #15
bowserface
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Alright, to hit your point in order:

(1) I'm not sure what you mean by "openvpn-key.txt.pub", maybe you mean the specific key file I'm trying to move? The key file contents I am trying to SCP are not the same as the contents of Authorized Keys in the .ssh directory.

(2) Also, the contents of the .pem file I use to connect to the remote machine via SSH is not the same as authorized key file either. Perhaps this is the issue?

(3) chmod to 600 and confirmed ubuntu is the owner

Code:
-rw------- 1 ubuntu ubuntu 389 Feb 17 19:00 authorized_keys
(4) /etc/openvpn is the folder path, the file I am trying to move is within that folder.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
SCP: Copy file from remote linux server onto a windows machine? Tony Empire Linux - Newbie 21 09-22-2015 10:18 PM
[SOLVED] Having trouble copying directories to remote machine using scp mothergoose729 Linux - General 1 09-29-2013 04:18 PM
[SOLVED] How can I ssh/scp into a remote's machine local machine? venom4u31 Linux - Newbie 6 11-05-2011 01:36 PM
scp: copy a file from local machine to remote machine seran Linux - Newbie 8 10-30-2007 12:23 PM
Running X-application on a remote AND local machine LinuxFrosh Linux - Software 1 07-04-2006 10:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration