You are not logged in.

#1 2013-05-10 18:44:48

ctlaltdefeat
Member
Registered: 2013-05-09
Posts: 5

Using pacman without sudo?

I've installed Archlinux recently, installed sudo and added my user to wheel group. Then I uncommented the line from visudo. I am able to use pacman with sudo, but not without (is it supposed to be like that? I don't know). Is it possible to somehow use it without writing sudo before all the time?

Offline

#2 2013-05-10 18:47:08

karol
Archivist
Registered: 2009-05-06
Posts: 25,433

Re: Using pacman without sudo?

You can use an alias

alias sp="sudo pacman "

You can use pacman w/o sudo for 'pacman -Q', 'pacman -Ss' etc.

Last edited by karol (2013-05-10 18:47:59)

Offline

#3 2013-05-10 19:08:40

zezhyrule3
Member
Registered: 2013-03-08
Posts: 65

Re: Using pacman without sudo?

If you could make changes to your system without root access, that would destroy the point of using sudo. 

For your own benefit you could make an alias like above, or something more like

alias pacman="sudo pacman"

Just put that in your .bashrc or .bash_aliases and then when you type 'pacman', bash will interpret it as if you wrote sudo in front of it. Of course if you did that, then it will ask for your password even when doing commands that don't require root (like -Q or -Ss). I have mine set up similar to what the Arch Wiki recommends, e.g.:

alias pacs="sudo pacman -S"
alias pacup="sudo pacman -Syu"
alias pacf="pacman -Ss"
alias pacq="pacman -Q"

Last edited by zezhyrule3 (2013-05-10 19:14:41)


- dots -

Offline

#4 2013-05-10 19:30:28

ctlaltdefeat
Member
Registered: 2013-05-09
Posts: 5

Re: Using pacman without sudo?

Thanks

Offline

#5 2013-05-10 19:53:16

karol
Archivist
Registered: 2009-05-06
Posts: 25,433

Re: Using pacman without sudo?

Please remember to mark the thread as solved https://bbs.archlinux.org/viewtopic.php?id=130309

Offline

#6 2013-05-10 21:11:11

jgreen1tc
Member
From: St. Louis
Registered: 2011-05-16
Posts: 247

Re: Using pacman without sudo?

I got this from a different section of the Arch forums about someone requesting this kind of function in zsh. If you have bash you can put the following in your .bashrc and calling `pacman` will only be done as root if pacman needs to be run as root.

pacman() 
{
    case $1 in
        -S | -D | -S[^sih]* | -R* | -U*)
            /usr/bin/sudo /usr/bin/pacman "$@" ;;
    *)      /usr/bin/pacman "$@" ;;
    esac
}

The problem with making an alias for pacman is that some actions don't require the use of sudo, so you would more likely want to create a separate alias for when you don't want to run pacman as a super user. This seemed to fix that for me.

Edit: I do not how it works so unless you do and feel comfortable, use at your own risk.

Last edited by jgreen1tc (2013-05-10 21:12:19)

Offline

#7 2013-05-10 21:15:52

progandy
Member
Registered: 2012-05-17
Posts: 2,151

Re: Using pacman without sudo?

I created 3 shortcuts: sp (sudo pacman), p (pacman), and pu  (sudo pacmanu -Syu)

Offline

#8 2013-05-10 21:17:55

karol
Archivist
Registered: 2009-05-06
Posts: 25,433

Re: Using pacman without sudo?

There's nothing wrong with e.g. 'sudo pacman -Q foo', you won't break anything, but you're right saying that this script is The Right Way (tm).

Offline

#9 2013-05-10 21:18:01

Primoz
Member
From: Ljubljana-Slovena-EU
Registered: 2009-03-04
Posts: 664

Re: Using pacman without sudo?

zezhyrule3 wrote:

If you could make changes to your system without root access, that would destroy the point of using sudo. 

For your own benefit you could make an alias like above, or something more like

alias pacman="sudo pacman"

Just put that in your .bashrc or .bash_aliases and then when you type 'pacman', bash will interpret it as if you wrote sudo in front of it. Of course if you did that, then it will ask for your password even when doing commands that don't require root (like -Q or -Ss). I have mine set up similar to what the Arch Wiki recommends, e.g.:

alias pacs="sudo pacman -S"
alias pacup="sudo pacman -Syu"
alias pacf="pacman -Ss"
alias pacq="pacman -Q"

I have even more extreme version of aliases:

alias S="sudo pacman -S
alias Syu="sudo pacman -Syu
alias Ss="pacman -Ss"
alias R="sudo pacman -R"

Yeah I'm that lazy.


Arch x86_64 ATI AMD APU KDE frameworks 5
---------------------------------
Whatever I do, I always end up with something horribly mis-configured.

Offline

#10 2013-05-10 21:35:19

jgreen1tc
Member
From: St. Louis
Registered: 2011-05-16
Posts: 247

Re: Using pacman without sudo?

I just re-read the OP and it seems like he is asking a different question than what we have been answering. I think he is saying that he can't use pacman unless he uses sudo. Is that the case OP? Can you try to run, for instance:

pacman -Ss iptables

and see if you get a result? I'm not sure if you are trying to simply use certain flags that require pacman to be run as root. If that's the case, and you don't want to use sudo before you call pacman with these flags, the advice we have given so far wont be useful.

Edit: I guess karol did touch on it.

Last edited by jgreen1tc (2013-05-10 21:36:49)

Offline

#11 2013-05-10 23:22:15

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,060
Website

Re: Using pacman without sudo?

If you want to use pacman without root privileges, you can allow the command in /etc/sudoers like this:
username hostname= NOPASSWD:  /usr/bin/pacman -Syu

Last edited by teateawhy (2013-05-10 23:22:36)

Offline

#12 2013-05-11 00:18:34

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 5,675

Re: Using pacman without sudo?

teateawhy wrote:

If you want to use pacman without root privileges, you can allow the command in /etc/sudoers like this:
username hostname= NOPASSWD:  /usr/bin/pacman -Syu

But that will create a gaping security hole and cannot be recommended.


How To Ask Questions The Smart Way | Help Vampires

Arch Linux | x86_64 | GPT | EFI boot | grub2 | systemd | LVM2 on LUKS
Lenovo x121e | Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz GenuineIntel | Intel Centrino Wireless-N 1000 | US keyboard with Euro | 320G 7200 RPM Seagate HDD

Offline

#13 2013-05-11 12:14:14

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,060
Website

Re: Using pacman without sudo?

cfr wrote:
teateawhy wrote:

If you want to use pacman without root privileges, you can allow the command in /etc/sudoers like this:
username hostname= NOPASSWD:  /usr/bin/pacman -Syu

But that will create a gaping security hole and cannot be recommended.

Now i am really interested in this point, but i do not want to hijack this thread.
As far as i know you pacman asks for your password when changing one letter of the command.

sudo pacman -Syu package
Password:

As /etc/pacman.d/mirrorlist can only be written by root, how could this be used against me?

Offline

#14 2013-05-11 20:59:08

Baryon
Member
Registered: 2011-08-12
Posts: 63

Re: Using pacman without sudo?

I personally don't use sudo... I just use su to become root. I imagine it counts as more secure? But I do it just because I find it more intuitive. It certainly beats having to have different pacman aliases depending on whether the pacman command requires root privileges or not.

Offline

#15 2013-05-11 21:29:40

BasT
Member
Registered: 2010-08-28
Posts: 78

Re: Using pacman without sudo?

Just use pacaur. It will ask for sudo password only if it needs it.

Offline

#16 2013-05-11 21:52:09

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,060
Website

Re: Using pacman without sudo?

BasT wrote:

Just use pacaur. It will ask for sudo password only if it needs it.

Pacman, too. If you dont type sudo...

Last edited by teateawhy (2013-05-11 21:52:38)

Offline

#17 2013-05-11 22:36:36

jgreen1tc
Member
From: St. Louis
Registered: 2011-05-16
Posts: 247

Re: Using pacman without sudo?

teateawhy wrote:
BasT wrote:

Just use pacaur. It will ask for sudo password only if it needs it.

Pacman, too. If you dont type sudo...

Why would it ask for sudo password if you don't type sudo?

Offline

#18 2013-05-11 22:55:44

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,060
Website

Re: Using pacman without sudo?

Sorry, i was not clear enough. I wanted to say that pacman can be used without root for example for 'pacman -Q'. It will not ask for password then.

Offline

#19 2013-05-12 02:50:36

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 5,675

Re: Using pacman without sudo?

teateawhy wrote:

As far as i know you pacman asks for your password when changing one letter of the command.

sudo pacman -Syu package
Password:

As /etc/pacman.d/mirrorlist can only be written by root, how could this be used against me?

You're right. I didn't realise sudo worked like that. I still worry that it may open a security hole but certainly a much less straightforward one.


How To Ask Questions The Smart Way | Help Vampires

Arch Linux | x86_64 | GPT | EFI boot | grub2 | systemd | LVM2 on LUKS
Lenovo x121e | Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz GenuineIntel | Intel Centrino Wireless-N 1000 | US keyboard with Euro | 320G 7200 RPM Seagate HDD

Offline

#20 2013-05-12 04:11:42

progandy
Member
Registered: 2012-05-17
Posts: 2,151

Re: Using pacman without sudo?

cfr wrote:

You're right. I didn't realise sudo worked like that. I still worry that it may open a security hole but certainly a much less straightforward one.

I don't see a real security hole, but there is a problem. Imagine an update that needs manual intervention (e.g. update config files) and some regular user performs it. As a result the next reboot will be a challenge. The admin first has to trace the problem to the update and then fix it before the regualr users can boot again.

Offline

#21 2013-05-12 13:21:21

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,060
Website

Re: Using pacman without sudo?

progandy wrote:
cfr wrote:

You're right. I didn't realise sudo worked like that. I still worry that it may open a security hole but certainly a much less straightforward one.

I don't see a real security hole, but there is a problem. Imagine an update that needs manual intervention (e.g. update config files) and some regular user performs it. As a result the next reboot will be a challenge. The admin first has to trace the problem to the update and then fix it before the regualr users can boot again.

Yes, in a scenario with admins and regular users,  users should not be allowed to use sudo / root .

Offline

Board footer

Powered by FluxBB