Solved

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

Posted on 2004-03-22
7
374 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
Comment Utility
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
Comment Utility
If you don't want to put "." on the search path, then just do:

./progname ...

0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 9

Assisted Solution

by:Alf666
Alf666 earned 50 total points
Comment Utility
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
Comment Utility
Hi, did any of these answer reply to your question ?
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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
Comment Utility
Thanks for the added depth Alf666.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now