Does SSH Access Cause Permission Issues on Raspberry Pi?

  • Thread starter Thread starter TheDemx27
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around permission issues encountered when executing a Python script on a Raspberry Pi, particularly in the context of accessing the device via SSH. Participants explore potential solutions and clarify aspects of Linux file permissions and script execution.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant reports a "Permission denied" error when trying to execute a Python script and mentions SSH access as a possible factor.
  • Another participant suggests running the script using the Python interpreter directly as an alternative to executing it as a file.
  • Several participants emphasize the need to set the script as executable using the command chmod +x test.py and to include a shebang line at the top of the script to specify the interpreter.
  • One participant provides a command to check if Python is in the user's PATH and another to check the file's permissions, explaining the output format of the permission settings.
  • There are repeated expressions of confusion regarding the Raspberry Pi context, with participants questioning the relevance or specifics of the device.

Areas of Agreement / Disagreement

Participants generally agree on the need to set executable permissions for the script and the importance of the shebang line. However, there is no consensus on whether SSH access is directly related to the permission issues being experienced.

Contextual Notes

Some participants mention specific commands and outputs related to file permissions, but there is no resolution on the underlying cause of the permission issue or the impact of SSH access.

Who May Find This Useful

Users experiencing similar permission issues on Linux systems, particularly those using Raspberry Pi and Python scripts, may find this discussion relevant.

TheDemx27
Gold Member
Messages
169
Reaction score
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
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   Reactions: 1 person
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).
 
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?
 
:confused: raspberry pi?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • Sticky
  • · Replies 48 ·
2
Replies
48
Views
70K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K