0

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 :)

Belgin Fish
  • 919
  • 5
  • 17
  • 31

5 Answers5

6
sudo -u <another_user> /path/to/filename.ext
quanta
  • 51,413
  • 19
  • 159
  • 217
3

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.

user9517
  • 115,471
  • 20
  • 215
  • 297
2

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.

voretaq7
  • 79,879
  • 17
  • 130
  • 214
  • +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
1

Take a look at sudo.

coredump
  • 12,713
  • 2
  • 36
  • 56
0

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)

Silent-Bob
  • 1,066
  • 6
  • 9