Solved

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

Posted on 2004-03-22
7
393 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 50 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 9

Assisted Solution

by:Alf666
Alf666 earned 50 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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