Getting out of the local permissions / server login catch 22

Key words and phrases: 
authorized keys
Description & Info: 

The first step to getting out of the local permissions / server login catch-22 is to know you're in it.

Perhaps you found this page searching for "Permission denied on publickey even though I can log into the server with a public key it doesn't make any sense grrr argh how dare it deny me i created it why won't it work permissions are correct this isn't right" or something like that.

Your problem is that when you run the command without sudo, you don't have the proper permissions locally, and your computer doesn't even try to connect to the server:

Ebony-II:default ben$ scp -r ben@agaricdesign.com:/var/www/drupal-5_2-live/sites/anjaliforberpratt.com/files files
files: Permission denied

But when you add sudo in front, you are actually trying to log into the server from your local computer's root user account, which does not (in this case) have its public key (id_dsa.pub or id_rsa.pub cat'ed to authorized_keys on the server's root account).

Ebony-II:default ben$ sudo scp -r ben@agaricdesign.com:/var/www/drupal-5_2-live/sites/anjaliforberpratt.com/files files
Permission denied (publickey).

What to do? You could download the files you want into your home directory or somewhere else you have permission... or use your sudo powers to make sure you will never get permission denied locally!

Ebony-II:default ben$ sudo chmod 777 .

Now, the non-sudo version of the command works:

Ebony-II:default ben$ scp -r ben@agaricdesign.com:/var/www/drupal-5_2-live/sites/anjaliforberpratt.com/files files

Thank you, and this solution has been brought to you by the How-did-it-take-so-long-to-figure-that-out Foundation.

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.