Does SSH Access Cause Permission Issues on Raspberry Pi?

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

The discussion addresses permission issues encountered when executing Python scripts on a Raspberry Pi via SSH. Users must ensure that the script has executable permissions by using the command chmod +x test.py and include the shebang line #!/usr/bin/python at the beginning of the script. If the script does not have the correct permissions, it will result in a "Permission denied" error. Additionally, users can run the script directly with the Python interpreter using python test.py without modifying file permissions.

PREREQUISITES
  • Basic understanding of Linux file permissions
  • Familiarity with SSH access and command-line interfaces
  • Knowledge of Python scripting
  • Experience with executing commands in a Linux environment
NEXT STEPS
  • Learn about Linux file permissions and how to modify them effectively
  • Explore the use of shebang lines in various scripting languages
  • Investigate the PATH environment variable and its impact on command execution
  • Study common SSH troubleshooting techniques for Raspberry Pi
USEFUL FOR

This discussion is beneficial for Raspberry Pi users, Python developers, and anyone troubleshooting script execution issues in a Linux environment.

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
68K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K