Fallenreaper
Fallenreaper

Reputation: 10684

Server gives me a permission error when trying to scp, but not when ssh

Is there server configuration you need to set when you want to scp to a server? If i ssh into the machine, i use:

ssh -i file.pem user@server

but when i try the scp command, it will give me a permissions error.

scp path/to/file.pdf -i file.pem user@server:/home/user/.

What am i doing wrong, and how can i fix it? I cant seem to figure out what's up with it. The error reads as:
Permission denied (publickey). lost connection

Upvotes: 1

Views: 973

Answers (1)

prodigitalson
prodigitalson

Reputation: 60413

You need to shuffle around your options and arguments. It should be:

scp -i file.pem path/to/file.pdf user@server:/home/user

Note the omission of /. from the end of the target path. It is not necessary because if the last segement of the target is a dir it will copy the files into the directory, just like cp and mv.

Is there a way to assign the file.pem such that it just picks it up when i use: user

You can do that with an ~/.ssh/config config file:

Host            serveralias
HostName        server.com
User            user
IdentityFile    /path/to/your/key.pem

After creating that you can do:

# will effectively be like doing 
# ssh -i /path/to/your/key.pem [email protected]
ssh serveralias

Or

# should pick up on the same settings and effectively like 
# ssh -i /path/to/your/key.pem [email protected]
ssh [email protected]

And they should both use the IdentityFile you specified.

Upvotes: 1

Related Questions