0

I have two different machines and I tried to copy a file via SCP. I executed below command:

scp trial.txt [email protected]:/unixStudy/trial.txt

and then I got "Permission denied" error even though I typed correct password for user root.

I searched a little bit and I gave permission for the scp file to be executable by other users on target machine, but it still didn't work.

6
  • What was the exact error message you received? Don't paraphrase it. Commented Aug 1, 2019 at 15:43
  • Is root allowed to use ssh or scp on remote host? Commented Aug 1, 2019 at 16:00
  • Are you allowed to read trial.txt locally? Commented Aug 1, 2019 at 16:06
  • Try running the scp command again, in verbose mode. The extra information may help you troubleshoot the problem. Commented Aug 1, 2019 at 16:22
  • I've realized that I should have mentioned ssh. I can ssh to other machine as root or any other user. Commented Aug 2, 2019 at 10:20

2 Answers 2

1

SSH (secure shell) is the fundamental protocol in play. SCP (secure copy) does the copy process once the SSH connection has been established. As such, the SSH server on the system being connected to with the scp command has to be properly configured for starters.

Very common for /etc/ssh/sshd_config to contain PermitRootLogin = no. Because you said tried to scp and typed root password if you are doing an scp trying to connect to whatever computer as root, you would be denied.

solutions:

  • do a simple ssh connection first instead of using scp and make sure that works for the given usernames. If it does not, then scp under those same parameters will not work. Syntax is ssh username@systemname If successful with ssh username@systemname then doing a corresonding scp username@system://path_to_file/filename /location_on_current_system should work
  • possibly modify /etc/ssh/sshd_config and change PermitRootLogin yes then restart the sshd daemon/service. Typically permitrootlogin=no for security reasons but depending on your environment may be irrelevant. Your call. If you must connect to the computer acting as the ssh server as root, then you need to change this in sshd_config.

also realize if you're logged in as username abc123 then doing

scp            othersystem:/path_to_file/filename      .

is effectively the same as

scp     abc123@othersystem:/path_to_file/filename     .

make sure you are connecting using the correct passwords with a valid username.

Also, in case you thing typing the root password trumps the existing password it does not; you have to type the correct password for the given account name being used.

1
  • Hi, thanks for detailed answer. I can ssh to target machine which is in same network. Then I tried the steps you mentioned and still get the same error. I'm sure that I'm using correct username and password. Commented Aug 2, 2019 at 10:31
0

You can simply remove trial.txt after /unixStudy/.

And, make sure you have correct permission to write in to the /unixStudy directory on remote server.

scp trial.txt [email protected]:/unixStudy/trial.txt

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.