Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't run executable with file and directory permissions set for executable

Posted on 2004-03-22
7
Medium Priority
?
413 Views
Last Modified: 2010-04-20
Just started poking around some linux distros (knoppix, libranet, mandrake) and I'm mystified why I cant run a small 'hello world' kind of executable. I chmod'd the file and directory to 777, tried doing it with root account, all I get is a command not found errors. Doing a ls -al I can see that the file and directory do have executable permissions. Bash recognizes the file as an executable by showing it in green. The file is in my /home directory. I finally got it to work by using root and placed the file in my /sbin directory. What is preventing me from running under /home ????
0
Comment
Question by:Jebtrix
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 2

Author Comment

by:Jebtrix
ID: 10654895
Nevermind I figured out I needed the full path name unless its in $PATH. Let me rephrase the question, is there anyway I can run the executable without full path and without adding current directory to global $PATH var? Like autoappending path if file is in current folder or something along those lines.
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 200 total points
ID: 10654925
If you don't want to put "." on the search path, then just do:

./progname ...

0
 
LVL 21

Expert Comment

by:tfewster
ID: 10655750
Don't forget to remove the test executable from /sbin & change the directory permissions back to 755 -
It's not too important if only you use this machine, but it''s never too early to learn good habits ;-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Assisted Solution

by:Alf666
Alf666 earned 200 total points
ID: 10660124
I'd like to add my two cents here on different topics :

1) Executing with the right path :

- Using full path : /home/myname/myproggie
- Using relative path : ./myproggie or ../myproggie or ./myproggies_dir/myproggie

The PATH variable will only be used if the prog can't be found directly with the command you gave (including a path).

2) The files and dirs access rights

Directories will never need 777.
1 will allow you to cd inside it (or access/execute) whatever file is inside it.
2 will allow you to write inside of it. Which means you can't create or delete a file from it. But, if you have write access on a file, you will be able to modify it.
4 will allow you to read it (usefull to know what's inside of it)

In fact, the access rights on a directory will allow you to modify it's structure (directories used to be some kind of special files, so to say).

An exe will never need 777 either. An executable will need 1 at least. A shell script will need 1 + 4 (it needs to be read before beeing evaluated).

And, in the future, you might encounter similar problems if you write a shell script which has the proper access rights but does not begin with a shell command to help the system identify which shell command will be used to "run" it. So, all your scripts have to begin with :
#!/bin/bash

(for example, assuming bash is in /bin, and you want to use bash).

3) A few infos about security

To reply to your question, you can add "." to your PATH. But :

If you ever care about security, you should avoid having "." in your PATH. If you really want it, it should be the last element. If you do, and you work as root, any clever hacker might add a command like "ls" in /tmp for example, and, the next time you cd to /tmp, you will execute the malicious program.

So, the simplest suggestion is :

export PATH=${PATH}:.
(assuming your default shell is bash).

You could add this line to your .bashrc or .bash_profile (in your home directory).
0
 
LVL 9

Expert Comment

by:Alf666
ID: 10682471
Hi, did any of these answer reply to your question ?
0
 
LVL 21

Expert Comment

by:tfewster
ID: 10683117
IMHO - brettmjohnson gave the first valid answer, but Alf666 gave an excellent tutorial on paths & permissions.  Unless Jebtrix wants to request a refund at http://www.experts-exchange.com/Community_Support/  I suggest splitting the points between them ;-)
0
 
LVL 2

Author Comment

by:Jebtrix
ID: 10715947
Thanks for the added depth Alf666.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month6 days, 12 hours left to enroll

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question