Solved

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

Posted on 2004-03-22
7
382 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 20

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 20

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Squid Connection Pools 3 45
route 2 traffic streams on single NIC 6 35
Setting up Two Three NICs with One on a Different Subnet 22 57
Hacked File Timestamps 4 49
Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
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…
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

911 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

21 Experts available now in Live!

Get 1:1 Help Now