Question

I'm on a 64-bit Centos 5 Linux. This comes with Python2.4, but I needed 2.6 or higher to get psycopg2. I installed a virtual environment to run Python2.7.3 (based on this http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/) Now things seem to be working well when I'm logged in as root.

But I need to be able to use the virtualenv as a non-root user, joshmoe. (And start/stop postgresql as this other user)

The command for getting into the virtualenv is:

source /root/Python-2.7.3/projectdir/bin/activate

Understandably, when I run this command as joshmoe, I get a permission denied message:

-bash: /root/Python-2.7.3/projectdir/bin/activate: Permission denied

In an attempt to make this command available to joshmoe, I edited /etc/sudoers to include the following line:

joshmoe ALL=NOPASSWD: /root/Python-2.7.3/projectdir/bin/activate

Now from the joshmoe login, when I run:

sudo source /root/Python-2.7.3/projectdir/bin/activate

I get the following:

sudo: source: command not found

It seems pretty clear to me that I'm not using the sudoers file correctly to specify sourcing this file -- I seem to be giving access to that 'activate' file successfully, but not to the built-in source function. Either of following lines give syntax errors in sudoers:

joshmoe ALL=NOPASSWD: source 

joshmoe ALL=NOPASSWD: source /root/Python-2.7.3/projectdir/bin/activate

I've found a good many examples of shudders statements. But I can't figure out the syntax that will make this work. I'm hoping once I get this one, I'll be able to give access to statements like 'service postgresql status' and so forth.

Was it helpful?

Solution

Your problem is that you user doesn't have root access to your virutalenv directory. You need to grant the user access for it to work, for example using:

sudo chmod o+x /root                     # grant access to root directory
sudo chmod o+rX /root/Python-2.7.3 -R    # recursively grant access to everything in Python-2.7.3

source isn't a program, it's a shell butiltin which causes a script to be sourced in the current shell. sudo can only execute programs, not shell builtins, functions or aliases, that's why you get that error.

OTHER TIPS

You can't run source as as sudo source; it's a built-in command for bash, not a program. What you want to do here is probably start a new shell as superuser using sudo -s.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top