Does SSH Access Cause Permission Issues on Raspberry Pi?

  • Thread starter Thread starter TheDemx27
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 13K views
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.
 
Physics 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?