2

I am trying to do both upload / download file into my server using ubuntu command lines but somehow it keeps on giving me permission denies. I have tried using -F and -i both doesn't work.

I tried something like

sudo scp -v /path/to/my/file/ ubuntu@ip-xx-xxx-xxx-xx:~/path/to/where/upload
sudo scp -v -i ~/.s/path/to/my/file/ ubuntu@ip-xx-xxx-xxx-xx:~/path/to/where/upload
sudo scp -v -F ~/.ssh/xxx.pem /path/to/my/file/ ubuntu@ip-xx-xxx-xxx-xx:~/path/to/where/upload

the above is just trying to upload. Same for download too but of course reversed the order but didn't work too. For download, I used terminal to log into the server already and used something like this but in reverse sudo scp -v /path/to/my/file/ ubuntu@ip-xx-xxx-xxx-xx:~/path/to/where/upload

EDIT:

Getting errors like such and also, I tried using touch and able to make files without a problem too

debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:QgAQzu59hpmTEGkNnOdEeflCYVImcwLLU3qQD7foqbE
debug1: Host 'ip-xxx-xx-xx-xx' is known and matches the ECDSA host key.
debug1: Found key in /home/ubuntu/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/ubuntu/.ssh/id_rsa
debug1: Trying private key: /home/ubuntu/.ssh/id_dsa
debug1: Trying private key: /home/ubuntu/.ssh/id_ecdsa
debug1: Trying private key: /home/ubuntu/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
Zanna
  • 70,465
Dora
  • 445
  • 1
  • 9
  • 22

3 Answers3

2

The relevant messages are here:

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/ubuntu/.ssh/id_rsa
debug1: Trying private key: /home/ubuntu/.ssh/id_dsa
debug1: Trying private key: /home/ubuntu/.ssh/id_ecdsa
debug1: Trying private key: /home/ubuntu/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

The SSH server (the other computer) you're connecting to only accepts public key authentication (rather than some other method like entering a password), and none of your public keys on the SSH client (the computer you're at) have been added to ~/.ssh/authorized_keys on the SSH server. To fix that:

  1. Log onto the SSH server as the user ubuntu
  2. Copy the contents of the SSH client's ~/.ssh/id_rsa.pub file (or one of the other .pub files in ~/.ssh) into the SSH server's ~/.ssh/authorized_keys file
  3. Try connecting to the SSH server by running ssh ubuntu@whatever on the SSH client
Chai T. Rex
  • 5,193
2

You have a few sets of issues.

First you have to differentiate permission locally, where you run scp, and on the server.

Second you have to understand when you run scp with sudo you are running scp as root and that affects local permissions. Running scp as root does not affect permissions on the server as you are accessing the server as ubuntu.

I think a large part of your problems start because you are running scp as root (with sudo)

Start with running scp or ssh as your regular user. My guess is that because you have been running scp as root your permissions of ~/.ssh and your keys is all wrong.

sudo chown $YOUR_USER:$YOUR_USER ~$YOUR_USER/.ssh

see http://bodhizazen.com/Tutorials/SSH_keys and http://bodhizazen.com/Tutorials/SSH_security

Next, your login user has to have permission to access files on your local machine /path/to/my/file/ and the server user, "ubuntu" has to have permissions to access files on your server, ~/path/to/where/upload

If you have specific question beyond that advice I need specific details.

Local user name , exact files you are transferring, ownership and permissions on the local machine and server, both ~/.ssh and files to transfer, and the exact command(s) you are running and all the output.

Panther
  • 102,067
-1

Your publickey might not work anymore. Try deleting the ECDSA key fingerprint.

You can find it in your /home/user/.ssh/known_hosts file on your desktop computer (note .ssh is an hidden folder and you have to select View -> Show Hidden Files from the file manager's menu). I normally delete the file even if there are multiple keys in the file.

ssh ServerUsername@xxx.xxx.xxx.xxx into your server and you will be asked to accept a new ECDSA key fingerprint. Make sure you use your server's username with both the ssh and scp commands. Finally the server's user should have right access to the folder on your server you copy the files into.