- How to resolve the «Permission Denied» error in Linux
- How to resolve permission denied Linux error
- What is permission denied Linux error?
- Example of Permission denied Linux error
- How to resolve Permission denied Error
- Resolving Permission denied error related to script execution:
- Resolving permission denied Linux error while listing or writing to a file
- Resolving permission denied Linux error for specific user
- Download Free book
- Ошибка bash permission denied
- Ошибка bash permission denied
- Выводы
- Ubuntu says «bash: ./program Permission denied» [closed]
- 3 Answers 3
- Linux Mint Forums
- [SOLVED] access permission denied in Linux 17.1
- [SOLVED] access permission denied in Linux 17.1
- Re: access permission denied in Linux 17.1
- Re: access permission denied in Linux 17.1
- Re: access permission denied in Linux 17.1
How to resolve the «Permission Denied» error in Linux
While using Linux, you may encounter the error, “permission denied”. This error occurs when the user does not have the privileges to make edits to a file. Root has access to all files and folders and can make any edits. Other users, however, may not be allowed to make such edits.
Remember that only root or users with Sudo privileges can change permissions for files and folders.
The permissions can be changed using the chmod keyword. The syntax for the command is:
chmod flags permissions filename
- flags are the additional options users can set.
- permissions define if the user can read, write, or execute the file. They can be represented using symbolic or octal numbers.
- filename is the name of the file whose permissions are changed.
Here is an example where users can read, write, and execute a file; whereas, group and others can only read it.
Here, each letter has a meaning:
r gives read permissions
w gives write permissions
x gives execute permissions
The same command can be run using octal notation:
Here, each digit represents the sum of the permissions allowed:
4 gives read permissions
2 gives write permissions
1 gives execute permissions
0 gives no permissions
The sum of these permissions is used to represent each type of author.
Источник
How to resolve permission denied Linux error
This article will teach you quickly what is permission denied Linux error. And also what ways you can avoid permission denied error in Linux.
What is permission denied Linux error?
This error comes when you try to list files or try execute the file inside the directory where you don’t have sufficient permission. Since Linux operating system is very particular about its security aspect.
Example of Permission denied Linux error
Let’s say you are a normal user who is trying to list or trying change the directory inside the /root file-system. Since you do not have sufficient permissions system will respond with permission denied error message as below:
One way to avoid such error is to switch to root user using su – command. However this solution is not recommended since it will gain unnecessary access to all the root file system.
How to resolve Permission denied Error
Resolving Permission denied error related to script execution:
Let’s say you have created a shell script for performing any task. but when you try to execute the script you may end with below error due absence of permission denied error.
Now to avoid such case you need to add execute permission “x” to the file myshell.sh using chmod command as below:
In the last output you can see that there is “x” (execution) permission added after chmod command. So next time when you try to execute the shell script , it will execute without any error.
Resolving permission denied Linux error while listing or writing to a file
In this type of permission denied error you try to list or write the file in which you do not have sufficient permission to do so as below:
If you look at the permissions of the “myfolder” directory using ls -l command you will come to know about the permissions.
As per the permission given in above output only owner of the directory who is root can have all permission that is read, write and execute. So in such case you need to change the permission of the directory to read using below chmod command:
Now this time when normal user manmohan try to list directory he will not get the permission denied error.
In case you want to have write permission on this directory you need to specify w flag as well in chmod command as below:
Same is applicable to file level permission as well.
One more way is to changing the ownership of the directory using chown command. Since in our example we are getting error for user manmohan we will change ownership of the directory “myfolder” using below command.
Since manmohan user is now the owner of the directory he can able to do any operation on the directory. In case you want to recursive permission do not forget to add -r while chown command as below:
Resolving permission denied Linux error for specific user
In above method of changing the permission using chmod is not suitable as per my opinion. Because when you give permission to others, it will be open for all the users within the system. Which is wrong in terms of security perspective. To resolve this error specific to user you can implement it using access control list or ACL. Follow my article on Access control list ACL for the same.
Download Free book
Get your free copy of Linux command line Cheat Sheet.
Источник
Ошибка bash permission denied
Многие новички пытаются выполнить запись определенных значений в системные файлы с помощью операторов перенаправления ввода и вывода и получают ошибку bash permission denied. Эта ошибка выводится, даже если вы использовали sudo.
Казалось бы, sudo есть, значит права суперпользователя получены и все должно работать но тут все не так просто. В этой статье мы рассмотрим почему возникает ошибка bash permission denied и как ее обойти.
Ошибка bash permission denied
Допустим, вы выполняете команду:
sudo echo «nameserver 8.8.8.8» >> /etc/resolv.conf
А в результате вместо записи строчки в /etc/resolv.conf получаете ошибку:
bash: /etc/resolv.conf permission denied
В русской локализации это будет отказано в доступе bash linux. Так происходит потому что вы запускаете с правами суперпользователя утилиту echo и она честно выводит вашу строку в стандартный вывод bash с правами суперпользователя. Но bash запущен от обычного пользователя, и когда интерпретатор bash пытается записать полученную строчку в системный файл, естественно, что вы получите ошибку.
Но существует несколько способов обойти это ограничение, вы можете, например, использовать команду tee, которая записывает стандартный вывод в файл или запустить саму оболочку от имени суперпользователя. Рассмотрим сначала вариант с tee:
echo ‘текст’ | sudo tee -a /путь/к/файлу
echo ‘nameserver 8.8.8.8’ | sudo tee -a /etc/resolv.conf
Это очень простое решение, но, кроме того, вы можете запустить оболочку bash с правами суперпользователя, чтобы дать ей доступ на запись:
sudo sh -c ‘echo текст >> /путь/к/файлу’
sudo bash -c ‘echo текст >> /путь/к/файлу’
sudo bash -c ‘echo nameserver 8.8.8.8 >> /etc/resolv.conf
Еще одно решение, призванное, упростить эту команду, добавить такой код в
sudoe() <
[[ «$#» -ne 2 ]] && echo «Usage: sudoe
» && return 1
echo «$1» | sudo tee —append «$2» > /dev/null
>
Дальше для вывода строки в файл выполняйте:
sudoe ‘текст’ >> /путь/к/файлу
sudoe «nameserver 8.8.8.8» > /etc/resolv.conf
Теперь все будет работать, как и ожидалось, и ошибка bash отказано в доступе не появится. Еще можно поменять права на файл, а потом уже выводить в него строку. Но это очень неправильное решение. И даже не потому, что это небезопасно, а больше потому что там намного больше действий.
Выводы
В этой небольшой статье мы разобрали почему возникает ошибка bash permission denied при использовании команды echo для системных файлов, а также несколько путей ее решения. Как видите, все достаточно просто. Надеюсь, эта информация была полезной для вас.
Источник
Ubuntu says «bash: ./program Permission denied» [closed]
Want to improve this question? Update the question so it’s on-topic for Stack Overflow.
Closed last month .
I am running Ubuntu on computer 1 and computer 2. I compiled a C++ program on computer 1, and I can execute it from the terminal using ./program_name . It runs fine.
However, when I try to do this on computer 2, it says: bash: ./program_name: permission denied
What’s wrong and what can I do about it?
3 Answers 3
chmod u+x program_name . Then execute it.
If that does not work, copy the program from the USB device to a native volume on the system. Then chmod u+x program_name on the local copy and execute that.
Unix and Unix-like systems generally will not execute a program unless it is marked with permission to execute. The way you copied the file from one system to another (or mounted an external volume) may have turned off execute permission (as a safety feature). The command chmod u+x name adds permission for the user that owns the file to execute it.
That command only changes the permissions associated with the file; it does not change the security controls associated with the entire volume. If it is security controls on the volume that are interfering with execution (for example, a noexec option may be specified for a volume in the Unix fstab file, which says not to allow execute permission for files on the volume), then you can remount the volume with options to allow execution. However, copying the file to a local volume may be a quicker and easier solution.
Источник
Linux Mint Forums
Welcome to the Linux Mint forums!
[SOLVED] access permission denied in Linux 17.1
[SOLVED] access permission denied in Linux 17.1
Post by ocaoca » Fri Feb 13, 2015 10:14 am
I have checked everywhere but I can not find an answer to my problem.
I have a PC with Linux 17.1 with an administration user ‘oscar’ and two other users ‘irati’ and ‘casa’. I also have a hard disk ‘old250’ where I want to share some files.
I have created a group called media where I have included casa and oscar users. (By the way I also have plex in this group and it also cannot access the files.)
As you can see below I have given all permissions to media group for /media/oscar and /media/oscar/old250.
However when casa or irati users try to access /media/oscar and /media/oscar/old250, the access is denied
So, why user casa can not access the folder it has group permissions to?
Is there alternative way to share files in a hard disk?
Does somebody know what ‘+’ means in the permission string drwxrwxr-x+?
Re: access permission denied in Linux 17.1
Post by Habitual » Fri Feb 13, 2015 11:29 am
is that the same ‘oscar’ as in oscar-desktop?
How did you add these users to media? Did they log out and back in for new group perms to ‘take’?
Did you umount and remount the resource after they did?
What’s the output of terminal >
Re: access permission denied in Linux 17.1
Post by altair4 » Fri Feb 13, 2015 12:48 pm
You really shouldn’t mess with the permissions of /media/oscar since it was created by the system. If you do change them it will work until is doesn’t. There may be a future update of something that returns it to the default.
Anywho, the way this was designed only oscar has permissions to get to whatever is mounted under it. It would be better to mount the partition under /media ( as in /media/old250 ) instead.
There is something else I should point out and it has to do with what you mean by «share».
If you wan’t a folder that all the other users can add to and remove files that will work in Mint.
If you want a folder where all the other users can add to, remove, but also edit each other’s files that will not work in Mint. ( edit ) unless the folder is in an ntfs partition.
If you want the latter I would suggest either using something like bindfs or switching to Ubuntu or something in the Ubuntu family instead.
Re: access permission denied in Linux 17.1
Post by karlchen » Fri Feb 13, 2015 1:17 pm
I do not quite understand what you have in mind with the last 2 sentences.
Ubuntu and Linux Mint share everything except the graphical desktop. So why should something be possible on Ubuntu that cannot be done on Mint?
By now the second sentence which I quoted (see above) has been «amended» to read
Actually, this «amendment» makes the statement completely wrong. It was wrong before. With the «amendment» it is totally wrong.
Below you will be given an example on how to create a folder «where all the other users can add to, remove, but also edit each other’s files.»
Actually whether everybody may modify a file inside a folder depends on the access permissions which have been assigned to owner, group, other on the file!
Therefore you will be given an example on how to create a file which everybody can read and modify, too.
All this will be done on Linux Mint 13, based on Ubuntu 12.04, and it will be done on the ext4 filesystem where Linux Mint 13 lives, not fat32 or ntfs filesystem involved or needed.
The example below makes use of the commands umask and chmod to make sure that the access permissions on the folder and on the files are set in such a way that full read and write permissions are granted to the owner, the owner’s group and others.
You need to understand that access permissions on folder and file objects depend on the object owner, his group and on others and on the permissions which have been assigned to the object owner, his group and others.
They do not depend on the starting value which a given Linux distribution for umask.
While I would not know of a way to change the umask inside a graphical file-manager, the command functionality of the comand chmod can be found inside the graphical file-manager as well.
Two more commands which help maintain access permissions are chown and chgrp. Their functionality can be found inside a graphical file-manager as well. (These 2 commands, however will not be used in the example below.)
Note:
Only the owner of an object will be permitted to use chmod, chown, chgrp on an object. Exception: root can do so on everybody’s objects.
2. How to create a folder with full access permissions for everyone:
If you want to make sure that everybody can create objects, modify objects and delete objects in a folder, create the folder like this
Obviously everybody has got full access to this folder.
Note:
What has been explained here using the commandline can be done using your graphical file-manager as well.
3. How to create a file with full access permissions for everyone:
3.1 How to use umask for this purpose:
Note:
I admit I do not know how to change the umask in a graphical tool. So the explained approach will have to be used inside a terminal window.
3.2 How to use chmod for this purpose:
Of course we can achieve the same result in a different way, too.
rw-rw-rw- for both files now.
Note:
What has been explained here using the commandline can be done using your graphical file-manager as well.
As the example above shows your statement, » If you want a folder where all the other users can add to, remove, but also edit each other’s files that will not work in Mint«, does not apply. It can be done and has been done. On Linux Mint 13.
All you have to know, understand and apply is .
- The Linux access permission concept which is based on owner, group and others and on the permissions which can be granted to owner, group and others. Find a brief explanation e.g. here: Permissions
- How to change access permissions using chmod. Find the instruction here:
5. Relevance to the thread starter ocaoca’s problem:
It would be possible to achieve the goal even if the users oscar, irati and casa were not members in a common user group. But in fact, they are.
This would allow for another little chgrp/chmod «trick», which makes use of the «S» bit for the group of the objects «media».
But explaining this is outside the scope of this post.
Источник