Score:0

Permission denied when trying to SCP files even though SSH works fine

in flag

I've SSHed successfully into a remote server and I'm trying to transfer some files between my local machine and the remote server using the SCP command.

When I try to transfer a file from the remote server to my machine while logged in the remote server I get a permission denied error:

alexa@server:~/project$ scp alexa@server:~/project/requirements.txt /mnt/c/Users/Alexa/Desktop/
alexa@server: Permission denied (publickey).

When I try to do the reverse and transfer a file from my local machine to the remote server while logged in my local machine I get this:

alexa@local:/mnt/c/Users/Alexa/Desktop/$ scp test_doc.txt alexa@server:~/project/
ssh: Could not resolve hostname server: Name or service not known
lost connection

I checked the permissions of all files and folders and alexa is the owner. Furthermore, I tried the same commands using sudo in front but the outcome was the same.

The debug shows this

debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/alexa/.ssh/id_rsa
debug3: no such identity: /home/alexa/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /home/alexa/.ssh/id_dsa
debug3: no such identity: /home/alexa/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/alexa/.ssh/id_ecdsa
debug3: no such identity: /home/alexa/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/alexa/.ssh/id_ecdsa_sk
debug3: no such identity: /home/alexa/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /home/alexa/.ssh/id_ed25519
debug3: no such identity: /home/alexa/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /home/alexa/.ssh/id_ed25519_sk
debug3: no such identity: /home/alexa/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /home/alexa/.ssh/id_xmss
debug3: no such identity: /home/alexa/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
alexa@server: Permission denied (publickey).

When I checked the content of /home/alexa/.ssh/ I only see 2 files:

alexa@server:~/.ssh$ ls -la
total 16
drwx------ 2 alexa alexa 4096 Jun 26 13:12 .
drwxr-xr-x 8 alexa alexa 4096 Apr 13 18:11 ..
-rw------- 1 alexa alexa  736 Apr  1 15:53 authorized_keys
-rw-r--r-- 1 alexa alexa  444 Jun 26 12:48 known_hosts

Any ideas what's causing this?

ar flag
Which distro and version of Linux are you running on the local computer and the remote server? Is the remote server a NAS? Please [edit your question](https://askubuntu.com/posts/1348366/edit) and add these information.
CrazyTux avatar
us flag
To transfer files between two pc's via ssh protocol you need to check that one of your machines can connect to the other, in your case, your own pc can connect the server so all you have to do is run the command correctly, `scp your_file_path destination` and more specific `scp /home/user/path_to_file/filename username@serverip:/path_to_destination` **you should run the command from your machine that could connect to the other machine** in your case from your own pc, if your server was able to connect your own pc you could run a similar (but different) command to get the files from you pc.
hr flag
Yeah it looks like you have connected to the server already via SSH and are then trying to connect to the server again via scp - the scp command that you are using should be run from the client (where you originally ssh'd from) instead
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.