Run command as user, not as root

Curt Carpenter

New Member
Joined
May 12, 2018
Messages
5
Reaction score
9
Credits
0
Hello!
I have a program in my /usr/bin directory named qspectrumanalyzer.

I can only execute this program if I switch to being root using the "su" command. I would like to be able to skip the change from being my normal user (curt).

Using ls -la to see how the program permissions are configured, I get the following result:

curt@curt-ThinkCentre-M58p:/usr/bin$ ls -la qspectrumanalyzer
-rwxrwxrwx 1 root root 228 May 11 22:17 qspectrumanalyzer


Any ideas of how I can make this program executable without switching to root? If I try executing as a normal user, I get the following message:

curt@curt-ThinkCentre-M58p:/usr/bin$ ./qspectrumanalyzer
Traceback (most recent call last):
File "./qspectrumanalyzer", line 7, in <module>
from qspectrumanalyzer.__main__ import main
ImportError: No module named 'qspectrumanalyzer'

Any suggestions welcomed -- I've run out of ideas :(!
 


Which Linux distro are you using? And how did you install qspectrumanalyzer?

The permissions clearly show that you should be able to execute it. It looks as if you have changed the permissions to 777 (Read, write and execute for ALL users) - which is definitely not advisable. I'd recommend setting that back to the more sane default of 755 (rwx for root, and rx for everybody else).

And from what you've posted, the program IS being ran. The error message you are getting is the python interpreter complaining that it can't find the qspectrumanalyzer module.

So if it runs OK as root, but not as a normal user, then it sounds to me like it has something to do with the way it was installed.

It seems to me that you may have somehow installed it for root only.

The main script for the program has been installed to /usr/bin/, but the rest of the python code for the application may have been put somewhere like /root/.local/bin or somewhere else that is inaccessible to normal users. That would be my guess!
 
Thanks for the reply. I really appreciate the insight. Your diagnosis is right on I think.

The program was originally installed in /root/.local/bin as you anticipated, which was impossible to get to without becoming root as you say, so I moved it and the components there to /usr/bin. The 777 permissions are the residue of my many attempts to get it to work from that directory without becoming root.

After moving the program and its components into /usr/bin, I can run it OK -- but still only if I become root first.

Could you tell me why a program like this would be put in an inaccessible directory like root/.local/bin? I'm sure the program author had some reason to do this, and I'm curious. I can always re-install the code in /root/.local/bin if there's some good reason to do that.

Thanks again for your input!
 
Offhand, I have no idea how you ended up installing it to /root/.local/bin/. But the fact remains that somehow you managed to install it to roots home directory instead of installing it system-wide. So it's either something you did, or there is a bug in the installation method which caused this to happen.

I've just found this page which documents how to install qspectrumanalyzer:
https://pypi.org/project/QSpectrumAnalyzer/

Perhaps try completely removing/uninstalling it and then re-install it. It might be worth restoring the files that were in /root/.local/bin/ before attempting the uninstall.

From the looks of things, you could try installing it via pip3, but without using sudo. That should install it to your home directory. (/home/yourusername/.local/bin/) - so it won't be available to other users. But if you are the only user on your PC, then that isn't really a huge problem!

Other than that, I don't know what to suggest.
 
I very much appreciate your help -- and you helped me solve my problem.:)

When installing the program, I ran the pip3 command described in the github install instructions while I was root. This was necessary to have access to root/.local/bin. It should have been obvious that "--user" was going to be "root," but it just didn't occur to me.

I just now ran the pip3 command again from my normal user account "curt", and I can now launch the program without being root. (This is with the program itself located in /usr/bin).

I guess I will need to try and learn something about python. I've never used it so it's all something of a mystery to me. For now though -- of to explore a few spectrums!

Thanks again.
 
Ah, that explains it!
I should have realised this last night. If you installed using:
Code:
sudo pip3 install --user qspectrumanalyzer
It would have the effect of installing the program locally for the root user, meaning that root would be the only user who could access it! This was your original problem and was where you originally went wrong.

To install the program system-wide you should have used:
Code:
sudo pip3 install qspectrumanalyzer
(As per the instructions in the link in my previous post.)

Note: no --user flag in the above, so pip will install the program system-wide for all users.
Also note: Using the above command without sudo would result in failure, because it requires root privileges in order to successfully install system-wide!

And using:
Code:
pip3 install --user qspectrumanalyzer
Note: no sudo/root
Will install the program locally, as the current user.

Re: misunderstanding
It wasn't that you were misunderstanding python per se. It was a misuse/misunderstanding of pip.
 

Members online


Latest posts

Top