При копировании ошибка permission denied

The SCP permission denied is an error message that is displayed when the user tries to copy files or data from a remote host that he does not have permission to access or tries to store the data in the root directory of his system, which does not allow the user to store data in it. In either of the cases, permission to access the data is required.

The SCP (Secure Copy Protocol) is a data transfer protocol explicitly used to copy data from one host to another over the network. The protocol runs on top of SSH (secured shell), which uses asymmetric cryptography to protect the data during transfers. Today we show you how to deal with protocol’s scp permission denied error.

Defining SCP

SCP utility running on windows.
SCP utility running on windows.

SCP is shot for secure copy protocol. It is an application layer protocol that works on top of the SSH protocol, a security protocol implemented between the application layer and the transport layer (TCP in this case). Scp command is compatible with all mainstream operating systems like Windows, Linux, macOS, etc. There are other similar protocols to the scp, such as SFTP (secure file transfer protocol), which transfers the data and performs data management functions. SCP comes pre-installed on macOS, Linux, and Windows. The user must have appropriate rights and permissions to avoid an scp permission denied error.

How to copy files using SCP

The scp command is not very complicated and simple to use. To perform any actions using the SCP without facing any permission error, you must have at least read permission on the remote host and otherwise write permission on the localhost. You might receive an scp permission error. The syntax of the command is intuitive and straightforward to use. Follow the given syntax to copy a file to the target location using scp.

scp [OPTION] user@src_host:file1 user@dest_host:file2

The OPTIONs are additional options that can be used to perform tasks according to the provided arguments. user@src_host:file1 is the file’s name to be copied prefixed with the username and address of the source host. And user@dest_host:file2 is the name to the resultant file with the specified address prefixed with the target host username and machine address. Use the -r option to copy all the files and subdirectories inside the folder recursively.

The scp permission denied error shows up when the users do not have the required rights or permission to perform a specific operation. Executable permissions are not required on any host while using the scp command. It requires read permissions on the source system and writing permission on the target system. There might be some ownership issue with the file or directory if you are receiving the scp permission denied error.

SCP permission denied ownership issue.

If the remote host’s directory from which the user is trying to copy the file or data is not owned by the username specified in the command, then an SCP permission denied error could be encountered. Follow the given steps to resolve this issue.

  • Login into the remost host with admin privileges.
  • Change the ownership of the directory to the USER instead of the root.
  • Use the chown (change owner) command to change the ownership.
  • Now run the scp command again.

Try using –verbose option

The -v or –verbose options are used to provide a detailed output of the program’s working. Use this option with the scp command to wisely observe the problems occurring under the hood and then troubleshoot the scp permission denied problem accordingly.

-v option along with the scp command.
-v option along with the scp command.

Use -P to specify the port number

Sometimes hidden or silent processes run on the arbitrary standard ports number on either host. For example, on the remote host, the chosen port number might be used by another process for another connection. Conflicting port numbers can also cause errors. Use the -P option to provide a specific arbitrary port number in such a case. NOTE – keep in mind that an uppercase -P is used to specify the port number while a lowercase -p is used for other purposes related to the original file.

Specifying the port number while using scp
Specifying the port number while using scp

SCP permission denied (publickey)

The SCP permission denied (public key) is an error message that the users are reported to face when they try to login to their AWS EC2 instance while using the passphrase-less authentication protocol such as ssh. The ssh passwordless authentication makes use of asymmetric cryptography to authenticate the user. If you provide the wrong private key to the scp utility, the scp permission denied error occurs. By default, the scp uses the default ssh private key directory to authenticate the user. Use the -i option to provide your specific private key file.

Scp permission denied resolved

Gcloud scp permission denied

Google provides cloud computing services in many forms. Google Compute Engine is one such way to use googles cloud services. The glcoud is a command-line utility tool that can interact with the cloud server. The cloud compute scp command is used to copy files from a google cloud virtual machine to your local computer. The syntax is almost similar to the SCP command. Complete documentation of the command can be found here.

If you receive an SCP permission error while copying data from your cloud host, then try downloading the content as the root user. Add @root before your destination or target address to resolve this issue.

gcloud compute scp /Users/File.tar root@local_machine:/home/Desktop

FAQs on SCP Permission Denied

Does the SCP utility come pre-installed with Windows?

Yes, it comes pre-installed on windows.

What is the extension of a private key file?

.pem, is the extension for private key files.

What is the shortcut for accessing the home directory in Linux?

~/, can be used in place of /home.

Conclusion

The SCP permission denied is one of the common errors that could happen during the use of SCP utility for copying files from one host to another. This article provided you with complete information regarding the SCP protocol. We discussed some of the ways and methods that could help in the scenario of the permission denied error.

Trending Now

  • Fixing Xtools XToolkit Installation Error

    Fixing Xtools XToolkit Installation Error

    March 3, 2023

  • Troubleshoot DeepMotion Preview Not Working: Tips and Tricks

    Troubleshoot DeepMotion Preview Not Working: Tips and Tricks

    by Dharam Nath JhaMarch 3, 2023

  • Getting Virtwifi has No Internet Access? Here’s What to Do!

    Getting Virtwifi has No Internet Access? Here’s What to Do!

    by Dharam Nath JhaFebruary 16, 2023

  • The Ultimate Guide to Fixing Wabbajack Failed Unknown Error

    The Ultimate Guide to Fixing Wabbajack Failed Unknown Error

    by Dharam Nath JhaFebruary 16, 2023

  • Печать

Страницы: [1]   Вниз

Тема: Permission denied немогу скопировать файлы  (Прочитано 5686 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн
d12brdsk

не могу скопировать файлы с рабочего стола в папку
/usr/share/stardict/dic
пишет ошибка Permission denied
копирую через nautilus, что делать?
PS: я начинающий пользователь

Мир портят EGOисты … давайте соблюдать ECOлогию общения!


Оффлайн
ende_neu

sudo nautilus
А в целом- man sudo.


Оффлайн
d12brdsk

ende_neu: спасибо все получилось.
а что дает: man sudo

Мир портят EGOисты … давайте соблюдать ECOлогию общения!


Оффлайн
ende_neu

man sudo- мануал по применению команды sudo  ;)
Вкратце-sudo-это выполнение программы от имени администратора.


Оффлайн
d12brdsk

man sudo- мануал по применению команды sudo  ;)
Вкратце-sudo-это выполнение программы от имени администратора.

Спасибо разобрался :coolsmiley:

Мир портят EGOисты … давайте соблюдать ECOлогию общения!


Оффлайн
olegik-hp

ИМХО sudo nautilus опасно использовать, ибо в графике убить что-либо проще…

Лучше sudo cp -R /source/ /dist/ или что-то в этом роде… man cp

1) Лучшая помощь — Линк на доку.
2) Главное — не просто сделать, а понять как.
3) Просто пару слов, для понимания — лучший ответ.


Оффлайн
iriver550

Если «привязан» к графике, то можно еще в терминале набрать sudo su или sudo -i. Когда зайдешь под root`ом набрать nautilus и откроется nautilus с правами админа. дальше, думаю, все понятно.


Оффлайн
Phoenix Corleone

а я куда лезу, то себе забираю
sudo chown мне что


Оффлайн
Malamut

Не-не-не-не, не слушайте Phoenix Corleone! Никогда так делать не стоит.

«Носителем суверенитета и единственным источником власти в Российской Федерации является ее многонациональный народ» Конституция РФ


Villain

Не-не-не-не, не слушайте Phoenix Corleone! Никогда так делать не стоит.

В домашней-то папке можно :) … Когда, например, с дисков что-то копируешь (документы, музыка и т.д.), можно сделать эту команду, чтобы файлы вам принадлежали и можно было делать с ними все, что угодно… А вот в системных папках так делать нельзя ни в коем случае >:( !!!

P.S. А лучше использовать midnight commander с правами root’а — и наглядно, и удобно.

« Последнее редактирование: 11 Января 2009, 12:13:42 от Villain »


Оффлайн
Malamut

Ну да, в домашней можно, ещё можно на подключаемых разделах с данными.
А вообще, что-то много вопросов по правам пошло. Читайте базовые учебники по Linux дабы отпали все вопросы по основам организации этой системы. Сразу кучу времени съэкономите на набивании вопросов на форуме))

«Носителем суверенитета и единственным источником власти в Российской Федерации является ее многонациональный народ» Конституция РФ


Оффлайн
axe

Не-не-не-не, не слушайте Phoenix Corleone! Никогда так делать не стоит.

В домашней-то папке можно :) … Когда, например, с дисков что-то копируешь (документы, музыка и т.д.), можно сделать эту команду, чтобы файлы вам принадлежали и можно было делать с ними все, что угодно… А вот в системных папках так делать нельзя ни в коем случае >:( !!!

когда копируешь, скопированные файлы и так принадлежат тебе, а права на них определяются значением umask. С правами на исходный файл это не имеет ничего общего. Совет Phoenix Corleone вреден (естественно, кроме тех случаев, когда ты абсолютно точно знаешь, что делаешь).


  • Печать

Страницы: [1]   Вверх

You have things in the right order from what I understand, the general way an scp is done is:

scp sourceuser@sourcehost:/path/to/source/file destinationuser@destinationhost:/path/to/destination/

Judging by your question, you have a local file you want to send to the destination server. So you have the right syntax which is good!

If you’re getting permission denied, then you’re not using the correct username or something’s amiss with the authentication. Most likely, it’s because the sudo command only works locally, for starters, so it won’t give you root on the remote box, so that’s probably the problem. Make sure that the user you are logging in as on the remote server has write permissions to the location you’re trying to write to.

If the problem is the destinationuser doesn’t have access to that location without sudo, move the file to the destinationuser’s home folder then sudo mv the file from the shell on the other server to put it in the right location.

I had the same problem.

Tried everything couldn’t fix it, until I checked my ISP Gateway.

I work with a Zyxel gateway from my ISP and because that is far away from where I have another terminal I shoved a old Linksys DD-WRT flashed Router/Repeater in between. My host terminal that was connected to that Linksys was first connected to the Gateway with a DHCP table lock (I ordered the gateway to give the MAC from that terminal the same IP via DHCP). I did this because I first had a NAS server on that mac. Now I moved the terminal to another location and totally forgot the mac ip assignment.

So now i had a WIFI repeater connected to the Gateway, and the computer with the mac assigned was connected to that.

The problem now was that my Gateway thought it was the old NAS whilst it was the other terminal, and assigned the IP to the WIFI repeater, and this was an IP conflict so scp couldn’t find the right location. Which on it’s turn resulted in a access denied on scp. Weird was that everything did work out fine, i could get on the internet, surf, mail, but with scp it gave an conflict.

Changed it in the Gateway (removed the DHCP table), and assigned another ip to the terminal…

Now scp command worked as before!

It took me 8 hours to figure it out so I thought to share this little hickup that can really frustrate you freaking butt off…

Greets
Pi @ir

SCP is an open SSH file transfer utility that you can use on Linux and other supported operating systems to transfer files over SSH. It can be used to transfer files between two hosts using an SSH connection.

The SCP ‘permission denied’ error can occur due to a variety of reasons, such as incorrectly specified paths or a writing permission error. We will explore some of the reasons as to why this error occurs and how to resolve it.

Cause : Not having write permissions 

One reason this error occurs is that your user does not have write permissions for the specific directory on the host where you are trying to write files. To check these permissions, you can use the ‘ls -l’ command, which will display the write permissions.

Look for a ‘w’ in the first four alphabets in the first column of the output. If you see one, it means your user has write permission for that directory. Alternatively, you can always create a file using the touch command in that directory. If you receive no errors, such as ‘permission denied,’ then it means your user has write permissions.

Example:

Let’s say you want to copy a file to a remote host using SCP, and you get permission denied because of write permissions.

scp abcd.txt user@127.0.0.1:/home/abcduser/abcd.txt

Solution 1 : Use the root account to transfer files

To fix such an error, you need to grant write permissions to your user for that directory. For that, you need root privileges or sudo. Another thing you can do is to copy the file to a directory where your user has write permissions.

In such a scenario, you either need to allow your current user the write permissions on /home/abcduser or you can use the root user account to copy that file.

To allow the root user to copy a file using scp, you need to allow root login on ssh which is not recommended for security reasons but you can use it anyway in such scenarios and disable it afterwards. 

To do that, open the openssh config at /etc/ssh/sshd_config and uncomment PermitRootLogin in a text editor in the remote host

Afterwards, connect to the remote host using its root account. 

Then run the command like this: 

scp abcd.txt root@127.0.0.1:/abcduser/abcd.txt 

Or simply this will do 

scp abcd.txt 127.0.0.1:/abcduser/abcd.txt

As they are both the same.

Solution 2: Add your user to the write permissions group:

To have a user write on a directory/file in linux, you either need to add a user to the group that owns the directory or file or make the file owned by that user. 

In our example, we run ls -l on the /home/ directory on the remote system to see which group owns /home/abcd. 

The ls -l command will give you an output, where the contents of the 4th column is the group which owns a corresponding directory/file.

In our example, it’s the abcduser group which owns the directory /home/abcduser then we can

Simply run this command on the remote system.

sudo groupadd user abcd 

It’s the ‘abcd’ group we want our user to be part of and the user we want to change the group of, is ‘user’. 

Run the ls -l command again and if you see a ‘w’ in the 6th place of the output in the first column, then it means the group has write permissions on that directory.

Then rerun the command again, which in our case would be:

scp abcd.txt user@somepc:/home/abcduser/abcd.txt

Solution 3: Use the user that owns that directory to copy the file 

The simplest solution of all is to use the user which owns that directory to copy the file to it. 

Simply run ls -l on the directory. In our case it would be: 

ls -l /home/

The output of the third column will be the user that owns that directory corresponding to the name of the directory you are interested in. In our case, it’s abcduser owns the directory /home/abcduser as seen in the screenshot above.

Then use that particular account while copying the file using scp to the remote host.
In our case, we run the command as follow:

scp abcd.txt abcduser@127.0.0.1:/home/abcduser/abcd.txt

Cause 2: Not having a private key for that user of the remote host 

You might get an error where it would say scp permission denied (public key) when you are trying to transfer files between hosts. 

That’s an authentication issue of ssh and the reason for that is you haven’t added a private key to scp while running it. 

Example: 

scp somefile user@127.0.0.1:/home/user/somefile.txt

Solution:

A simple fix for it is to run the scp command with the -i flag, thus adding the private key for that user using which you want to connect to the remote host and transfer files. 

You need to make sure you have the private key for that user and if you don’t, you need to generate it on the remote machine, and then have scp utility use it using the -i flag.

In our case, the solution would be: 

scp -i key.pem somefile user@127.0.0.1:/home/user/somefile.txt

Where key.pem is the private key file for the user ‘user’. 

Note: We have used 127.0.0.1 as the remote host just for example, in your case the remote host would likely be a remote machine and not your localhost.

Понравилась статья? Поделить с друзьями:
  • При копировании ошибка 0х80004005 неопознанная ошибка
  • При копировании на флешку выдает ошибку
  • При копировании данных на новый телефон произошла ошибка
  • При клонировании акронис выдает ошибку
  • При инициализации диска ошибка указано несуществующее устройство