Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have tried to SSH into my AWS ubuntu server and copy the directory to my local machine. Throughout the process I experience different file permission errors (noted below).

Is there one specific file permission needed for the .pem file that allows me to SSH and SCP?
Or do I need to change the file permission twice - once for SSH and another for SCP after I login?

Here are the commands I'm using:

SSH:

ssh -i sentiment.pem Todo@54.555.555.555

Copy from remote to local computer with:

scp Todo@54.555.555.555:/home/ubuntu/sentimentfolder /Users/Toga/Desktop/sentimentlocal

I'm on a Mac OS X 10.7.5, any guidance would be very much appreciated.


Trial and Error:

1.) After I initially downloaded the .pem file, its permissions were set to, I THINK: 0644

-rw-r--r--@ 1 Toga staff 1692 Feb 18 21:27 sentiment.pem

I then tried to SSH via terminal and received the following:

WARNING: UNPROTECTED PRIVATE KEY FILE! 
Permissions 0644 for 'sentiment.pem' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: sentiment.pem
Permission denied (publickey).

2.) I updated the file permissions to: chmod 660 sentiment.pem

After the update, the permissions were set to:

-rw-rw----@ 1 Toga staff 1692 Feb 18 21:27 sentiment.pem

I then tried to SSH via terminal and received the following:

WARNING: UNPROTECTED PRIVATE KEY FILE! 
Permissions 0660 for 'sentiment.pem' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: sentiment.pem
Permission denied (publickey).

3.) I updated the file permissions to: chmod 600 sentiment.pem

After the update, the permissions were set to:

-rw-------@ 1 Toga staff 1692 Feb 18 21:27 sentiment.pem

I then tried to SSH via terminal and was successful!!

4.) Now logged in, I run the a command to copy the remote directory to my local computer with:

scp Todo@54.555.555.555:/home/ubuntu/sentimentfolder /Users/Toga/Desktop/sentimentlocal

Which returns:

Permission denied (publickey).

SCP Commands Attempted:

1.) added the command -i and referenced the .pem file:

scp -i sentiment.pem Todo@54.555.555.555:/home/ubuntu/sentimentfolder /Users/Toga/Desktop/sentimentlocal

2.) added the command -i, referenced the .pem file, and changed the user for AWS to ec2-user:

scp -i sentiment.pem ec2-user@54.555.555.555:/home/ubuntu/sentimentfolder /Users/Toga/Desktop/sentimentlocal

3.) added the command -i, referenced the .pem filem, changed the user for AWS to ec2-user, and added the complete file path for the location of the .pem file:

scp -i /Users/Toga/Desktop/rollup/Personal/Serial_Project_Starter/sentiment/sentiment.pem ec2-user@54.555.555.555:/home/ubuntu/sentiment /Users/Toga/Desktop/sentimentlocal

share|improve this question

migrated from programmers.stackexchange.com Feb 19 at 3:31

This question came from our site for professional programmers interested in conceptual questions about software development.

    
You have to tell scp to also use the .pem file –  daniel kullmann Feb 19 at 5:54
    
thank you for calling that out @danielkullmann that makes sense. I tried a combination of commands that referenced the .pem file directly but nothing has worked yet. I have updated the question with a section titled: "SCP Commands Attempted" to catalog what I tried. If you an alternative command, please let me know. Thank you. –  George Jester Feb 19 at 8:22

3 Answers 3

yes the Permission want to be 400 for a pem file here is the Step by step guide for aws login How to Connect to Amazon EC2 Remotly using SSH

  1. Download and Keep the pem file.
  2. In Amazon Dashboard Choose Instances from Left side bar and choose the instance which we need to get connect
  3. Click on Actions and Choose Connect
  4. Click on Connect with a standalone SSH Client
  5. Open up a Terminal
  6. Create a Directory

    # mkdir -p ~/.ssh
    
  7. Move the Downloaded pem file to .ssh direcetory what we created

    # mv ~/Downloads/ec2private.pem ~/.ssh
    
  8. Change the permission of pem file to access only by root user

    # chmod 400 ~/.ssh/ec2private.pem
    
  9. Create a Config file for User

    # vim ~/.ssh/config
    

    Enter the Below Entry as your info In that Created config file

    Host *amazonaws.com
    IdentityFile ~/.ssh/ec2private.pem
    User ec2-user
    

    Save and Quit

  10. Then Copy the Public DNS Hostname and Paste in terminal and get connect
    eg :

    # ssh ec2-54-23-23-23-34.example.amazonaws.com
    

    And Press to get connect

share|improve this answer
    
I am curious: Why the downvote? –  erik Feb 19 at 11:25
    
I did NOT down vote this. This actually looks helpful, not sure if it will solve the problem for when I need to scp from the remote to my local comp. I will give this a try and see what happens. Thanks Babin. –  George Jester Feb 19 at 18:21
    
When copying an entire directory and its contents use scp -r. –  bahamat Feb 19 at 19:22

It seems you are not supposed to use the IP address, but the full host name of the system in the SCP command. The AWS docs describe this on http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html under the section "Transferring Files to Linux/Unix Instances from Linux/Unix with SCP".

And use -r to copy directories.

And note that the default user name is different for different images:

For Amazon Linux, the default user name is ec2-user. For RHEL5, the user name is often root but might be ec2-user. For Ubuntu, the user name is ubuntu. For SUSE Linux, the user name is root. Otherwise, check with your AMI provider.

So, use this command:

scp -r -i  /Users/Toga/Desktop/rollup/Personal/Serial_Project_Starter/sentiment/sentiment.pem ubuntu@ec2-xx-xx-xx-xx.compute-x.amazonaws.com:~/sentiment /Users/Toga/Desktop/sentimentlocal
share|improve this answer

The "Permission denied (publickey)" is from the remote server, so you're either using the wrong key, it's not allowed to connect or there's a typo in the remote authorized_keys file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.