0

i added a user a new user and would like them to be able to execute a file, when entering "python3" it works and i can enter code but when trying to execute python script i get this python3: can't open file 'bot.py': [Errno 13] Permission denied

  • [Errno 13] Permission denied sounds like the file is not readable. BTW I notice that you mention in comments that you are using rbash - if that's the case, please [edit] your question to include this information – steeldriver Sep 03 '19 at 21:54

2 Answers2

1

You could use this to change the script's ownership

sudo chown username:users bot.py

Or you can use this below, however it's better to find the minimum correct permissions you need for the file instead of granting it all permissions for everyone

sudo chmod 777 bot.py
Issam
  • 11
0

Hello and welcome on Ask Ubuntu :)

First thing, the error [Errno 13] Permission denied looks like a Windows error. Would you please confirm that you are running Ubuntu? If not, you can rather ask on stackoverflow or superuser. I'll answer for Ubuntu, but it would not be applicable if you are having this issue on Windows.
The user must have execution right on a file to be able to execute it. You can check access rights by opening a terminal, and type the command ls -l in the directory where the Python file is.
This command displays the access rights for all files/directories (something like -rwxrw-r--, with "r" for read, "w" for write and "x" for execute. The "-" means that the access right is not granted.), the group and user who owns the file and some other information.
There are 3 consecutive "rwx". The first one is for the file owner, the second one is for owner's group and the 3rd one is for all other users. They are usually referred as "UGO" for User-Group-Other. If the user who owns the file is the same as the user who needs to execute it, you'll need to have this kind of access right: -rwxrw-r--
There is a command to manage access rights: chmod You can grant the execution right to file owner with command sudo chmod u+x bot.py.
If the user who needs to execute the file does not owns it, then you'll need either to change the file owner with sudo chown command or grant execution right to "other" users (i.e. having access rights like -rwxrw-r-x with command sudo chmod o+x bot.py)
Please notice that chmod also allows to remove access rights - you need tu use "-" instead of "+" e.g. sudo chmod o-rwx bot.py would remove read, write and execution right of all users who don't belong to file owner's group.

You should be able to figure out how to grant correct rights to correct user with this. If not please do not hesitate to explain where you struggle and I'll provide mode details.

FloT
  • 2,326
  • the issue is im trying to allow each user to execute a specifi file, i run python3 and it all works but when im trying to execute a file i get the error and yes im on Ubuntu ```root@v100676:~# uname -v #67-Ubuntu SMP Thu Aug 22 16:55:30 UTC 2019
    
    
    – fortnite50 Sep 03 '19 at 20:58
  • So "sudo chmod o+x bot.py" should do the trick. What is the output of "ls -l"? – FloT Sep 03 '19 at 21:04