Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

hey well I login to my ssh client as the root user, since I don't know how to do it any other way and then why I try to run this script using the plain old

./filename.ext

an error log is generated saying it cant be run as the root user. I was wondering how I could make it so it's run as not the root user? I'm running debian

Thanks :)

share|improve this question
add comment

5 Answers

up vote 5 down vote accepted
sudo -u <another_user> /path/to/filename.ext
share|improve this answer
    
how do i create another user? :/ –  Belgin Fish Jul 28 '11 at 16:11
add comment

In broad terms you will need to create a non root user and then get them to run the program.

adduser fred
mkdir /home/fred
chown fred:users /home/fred
passwd fred

once you have done that you can try running your command with sudo

sudo -u fred ./filename.ext

In general you would be better off creating and using a non root account and then using sudo to run commands that require root privileges.

share|improve this answer
    
how can i add two directories for the user to access? –  Belgin Fish Jul 28 '11 at 16:52
    
How do you mean two directories ? –  Iain Jul 28 '11 at 17:35
add comment

First:

PLEASE DON'T LOG IN AS ROOT.

ESPECIALLY NOT OVER THE NETWORK.

Logging in as root is a BAD IDEA - One day you will make a typo that is fairly innocuous as a normal user, but can be catastrophic as root.
You should Create a normal, non-root user for yourself, and log in as that user. The procedures for this vary from distribution to distribution. This user should also be able to run the command in question (since they're not root), which solves the problem in your question.

Second, and semi-related: As others have suggested consider sudo for running the stuff you need to run as root (pretty much every linux distribution has it installed by default, or you can grab it from your package manager). This will require a bit of configuration (you will need to add the user to the sudoers file, or on some Linux distributions simply adding them to the admin group will suffice.
Alternatively you can simply use the su command to switch to root when needed. This lacks the flexibility of sudo, but requires no configuration on Linux systems - see the man page for su for more details.

share|improve this answer
    
+1 Also, if it's accessibly from the net, every script kiddie in the world tries to login as root first. –  Chris S Jul 28 '11 at 16:27
add comment

Take a look at sudo.

share|improve this answer
add comment

sudo would be my advice if you were user and needed to run the script as root (sudo requires configuration, before using it).

Vice versa, beeing root, and changing privileges to a normal user: use "su".

su -c "./filename.ext" $username

or to gain a login shell with the user privileges:

su - $username

(changing $username to the desired username)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.