Does SSH Access Cause Permission Issues on Raspberry Pi?

  • Thread starter Thread starter TheDemx27
  • Start date Start date
AI Thread Summary
The issue of receiving a "Permission denied" message when trying to execute a Python script on a Raspberry Pi is addressed by emphasizing the need for proper file permissions and the correct interpreter directive. To resolve this, the script must be made executable by using the command `chmod +x test.py`. Additionally, the first line of the script should specify the interpreter with `#!/usr/bin/python`. Alternatively, the script can be run directly using the Python interpreter with the command `python test.py`, which does not require setting executable permissions. Users are also advised to check if Python is in their PATH and to verify file permissions using `ls -l test.py`. Proper understanding of Linux file permissions is crucial for executing scripts successfully.
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 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?
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top