The SCP Command: Permission Denied Error

In this post, we will discuss SCP and SSH, Debugging, and potential causes of the SCP permission denied errors.

On this page
  1. Understanding SCP And SSH
  2. Debugging SCP
  3. Debugging SSH On The Remote Host
  4. Common Causes Of The Permission Denied Error
  5. Conclusion
  6. Additional Links

On Unix and Linux systems one of the go-to commands used to copy files is the SCP command. When everything is working that’s great but what if you run into an error? In this post, we will discuss SCP and SSH, Debugging, and potential causes of the SCP permission denied errors.

#Understanding SCP And SSH

The SCP command is available in Unix and Linux Operating systems. It’s used to securely transfer files between a local machine and a remote machine. This is done by transferring the files over an SFTP connection which transfers the data over an encrypted SSH Tunnel.

SSH stands for Secure Shell, it is one method for providing secure commutation over an untrusted network. It can be used for things like remote shell, file transferring, tunneling, and more.

#Debugging SCP

The SCP command has a verbose mode which is enabled by adding the -v flag to your command.

The below command is an example of what an SCP command would look like to copy a local file to a remote host. Though it was failing

Code
scp example.txt [email protected]:/destination_path/

Try adding the -v flag as shown below to get detained intonation.

Code
scp -v example.txt [email protected]:/destination_path/

This will provide you with more information as to what is happening during the attempt.

#Debugging SSH On The Remote Host

On the remote server (assuming it is a Linux server) there will likely be logs in one of the following locations:

  • /var/log/auth.log
  • /var/log/secure
  • /var/log/messages
  • Using the journalctl command

#Common Causes Of The Permission Denied Error

In this section, we will go over common causes for the permission denied error when trying to use SCP.

Invalid Login Credentials Or SSH Key Issues

The credentials or SSH Keys used to log in to the remote server need to be correct and allow you to gain access to be able to transfer the data.

To Correct

  1. Validate you have the correct username for the destination server.
  2. Validate you have a valid Password or SSH Key for the username in question.
  3. For ssh key authentication, you can specify the key you want to use with the -i flag. For Examplescp example.txt -i /path/to/ssh/key/ [email protected]:/destination_path/

File Permissions And Ownership Issues

The user running the command and the user on the remote server need to have permissions to read and write respectively.

To correct

  1. Confirm the correct users are being used.
  2. That file/directory permissions and ownership are correct.

Command Syntax

Another cause of issues when using the SCP command is mistakes with the command syntax.

To Correct

  1. Review the command for mistakes.
  2. Compare the syntax to the man page or other documentation to confirm if there is a mistake that might be harder to catch.

Incorrect Port

If the remote server has SSH configured on a non-standard SSH port this needs to be specified in your command.

To Correct

  1. Add the -P flag with the port number to the command. For Example:scp example.txt -P port [email protected]:/destination_path/

Incorrect Path Or Paths

If the file paths are incorrect this can also cause issues.

To Correct

  1. Verify both paths exist on their respective systems.

#Conclusion

In this post, we start by touching on SCP and SSH. From there we discussed debugging options for both SSH and SCP. Finally, we touched on reasons why you might get a permission denied error when trying to use the SCP command.

Done reading and looking for additional resources, why not check these out?

Illustrated avatar of CJ Saathoff
Written by

CJ Saathoff

CJ Saathoff writes for the NameHero blog.

More from CJ →