Does SSH Access Cause Permission Issues on Raspberry Pi?

  • Thread starter TheDemx27
  • Start date
In summary, the problem is that the file does not have the correct permissions to be executed. The solution is to change the permissions to allow the file to be executed.
  • #1
TheDemx27
Gold Member
169
13
I'm thinking this problem should be easy to fix.

I recently got a raspberry pi and did a few test python programs on it to make sure everything was working. Whenever I try to execute the python script I get this message:

Code:
pi@raspberrypi ~ $ ./test.py
-bash: ./test.py: Permission denied

I've tried changing permissions to the user pi, but it has no effect.
BTW: I'm accessing the pi from my desktop via SSH if that has anything to do with it.

Thanks.
 
Technology news on Phys.org
  • #2
Try

Code:
python test.py

If you want to run it directly you need to add a first line telling the shell what interpreter to use:

Code:
#!/usr/bin/python

print "Hello world!"
 
Last edited:
  • Like
Likes 1 person
  • #3
Look up Linux file permissions. To be very brief, you have to set the file to be executable before you can execute from the command line like you described. E.g. change the permission to allow the script to be executable:
Code:
chmod +x test.py
then you can run it like you were trying to:
Code:
./test.py
Also, like the previous post stated, you have to have:
Code:
#!/usr/bin/python
on the first line of the file to inform the shell what program is needed to execute it. This works for many languages (including Perl, PHP, Octave, etc).

Alternatively, you can just call the Python interpreter directly on files without that line, and without setting file permissions with:
Code:
python test.py
as long as "python" is an executable file in your PATH (something else you may want to look up).
 
  • #4
Code:
which python  # shows if python is in your PATH (environment variable)\
ls -l test.py   # shows if permissions allow execute
permissions look like this
-rwxrwxrwx

black - owner perms, blue - group perms red - "other" (world) perms

r = read permission
w = write permission
x = execute permission

So, I execute
Code:
ls -l test.py
and get

Code:
-rw-r--r--
It means the owner - you - cannot execute the file.

Code:
chmod 750 test.py
gives perms:
Code:
rwxrw----
Can you see if you now have execute permission?
 
  • #5
:confused: raspberry pi?
 
  • #6

1. What does "Permission Denied" mean in Raspbian?

"Permission Denied" in Raspbian means that the user does not have the necessary permissions to perform the requested action. This can happen when the user tries to access a file or directory that they do not have permission to view, edit, or execute.

2. How can I fix "Permission Denied" errors in Raspbian?

To fix "Permission Denied" errors in Raspbian, you can try changing the permissions of the file or directory using the "chmod" command. You can also try running the command with "sudo" to run it as the root user, who has higher privileges. If the issue persists, you may need to check your user's permissions and make sure they have the necessary access to the file or directory.

3. Why do I get "Permission Denied" when trying to install packages in Raspbian?

You may get "Permission Denied" when trying to install packages in Raspbian if you are not using the "sudo" command. Installing packages typically requires root privileges, so using "sudo" will allow you to install the packages with the necessary permissions.

4. Can I change the default permissions in Raspbian?

Yes, you can change the default permissions in Raspbian. However, it is not recommended to change the default permissions as it can potentially cause security issues. It is best to only change permissions on a case-by-case basis when necessary.

5. How can I view the current permissions of a file or directory in Raspbian?

You can view the current permissions of a file or directory in Raspbian by using the "ls -l" command. This will list the permissions for the file or directory in the following format: "drwxr-xr-x". The first character indicates the type of file (d for directory, - for regular file), followed by three sets of three characters indicating the permissions for the owner, group, and others, respectively.

Similar threads

  • Computing and Technology
Replies
1
Views
1K
  • Programming and Computer Science
Replies
6
Views
4K
  • Computing and Technology
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
17
Views
2K
  • Sticky
  • Aerospace Engineering
2
Replies
48
Views
60K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
Back
Top