You are not logged in.

#1 2025-04-26 15:47:18

notadaughter
Member
Registered: 2024-04-08
Posts: 14

[SOLVED] Alias systemctl

I aliased systemctl with `alias sc='systemctl'` in .bashrc. If i run `sudo sc ...` alias doesn't work anymore. I understand this is due to sudo spawning a new process.
I tried editing /root/.bashrc and few other things but nothing works. Is there a way to alias systemctl when using sudo?

Last edited by notadaughter (2025-05-02 20:07:21)

Offline

#2 2025-04-26 15:51:10

jl2
Member
From: 47° 18' N 8° 34' E
Registered: 2022-06-01
Posts: 678
Website

Re: [SOLVED] Alias systemctl

not a direct fix, but more the way I do it ...

I have these alias:

systemctl="sudo systemctl"
userctl="systemctl --user"

I have never need to un-alias systemctl


Why I run Arch? To "BTW I run Arch" the guy one grade younger.
And to let my siblings and cousins laugh at Arsch Linux...

Offline

#3 2025-04-26 16:55:05

seth
Member
Registered: 2012-09-03
Posts: 63,247

Re: [SOLVED] Alias systemctl

systemctl will use polkit to leverage credentials when necessary anyway?
You can simply skip sudo'ing it.

Offline

#4 2025-04-26 16:59:12

jl2
Member
From: 47° 18' N 8° 34' E
Registered: 2022-06-01
Posts: 678
Website

Re: [SOLVED] Alias systemctl

seth wrote:

systemctl will use polkit to leverage credentials when necessary anyway?
You can simply skip sudo'ing it.

doesn't that require typing in a password?
I use passwordless sudo (bad idea, I know, but fuck it, I already do autologin)

Last edited by jl2 (2025-04-26 16:59:53)


Why I run Arch? To "BTW I run Arch" the guy one grade younger.
And to let my siblings and cousins laugh at Arsch Linux...

Offline

#5 2025-04-26 21:57:19

mithrial
Member
Registered: 2017-03-05
Posts: 80

Re: [SOLVED] Alias systemctl

seth wrote:

systemctl will use polkit to leverage credentials when necessary anyway?
You can simply skip sudo'ing it.

Some commands require elevated rights before. E.g. systemctl edit ...

Offline

#6 2025-04-27 06:01:32

seth
Member
Registered: 2012-09-03
Posts: 63,247

Re: [SOLVED] Alias systemctl

@jl2, polkit allows you to configure yourself into a CVE, too tongue
@mithrial, indeed - looks like a straight up systemd bug, though.

You cannot sudo some_alias because sudoe executes executables, not aliases.
You could simply symlink systemctl to sc, but since systemctl inspects it args[0], that could run you into probles.
=> possibly a wrapper script that also parses the commandline and automagically involves sudo when necessary?

Offline

#7 2025-04-27 06:06:58

StubbledBannana
Member
Registered: 2025-04-27
Posts: 2

Re: [SOLVED] Alias systemctl

im confused on why you need to alias or unalias systemctl can you explain more on what your trying to do to give a solution

Offline

#8 2025-04-27 06:11:43

seth
Member
Registered: 2012-09-03
Posts: 63,247

Re: [SOLVED] Alias systemctl

echo sc | wc
echo systemctl | wc

cp, rm, mv, dd, …
http://blog.xkcd.com/2007/08/14/mirror … -the-lazy/

IT'S BECAUSE WE'RE LAZY!

Offline

#9 2025-04-27 06:12:56

lvsl
Member
Registered: 2024-08-22
Posts: 11

Re: [SOLVED] Alias systemctl

sudo your-alias

This one will not work. Instead do this

In your .bashrc, you add this line for example, to turn on bluetooth every time it starts, should the systemctl enable command does not work as nicely as it wanted

alias turnonbt='sudo systemctl start bluetooth'

But I don't recommend setting an alias in order to skip typing the word sudo in any way. I think it's just best practice. Unless I am entirely sure that I won't do anything stupid at all. Moreover if you had type sudo for your last commands (time limit for sudo), the alias you set will happily execute your sudo command without even asking you

Last edited by lvsl (2025-04-27 06:16:18)

Offline

#10 2025-04-27 06:31:29

jl2
Member
From: 47° 18' N 8° 34' E
Registered: 2022-06-01
Posts: 678
Website

Re: [SOLVED] Alias systemctl

seth wrote:

cp, rm, mv, dd, …
http://blog.xkcd.com/2007/08/14/mirror … -the-lazy/

IT'S BECAUSE WE'RE LAZY!

Wait there's a blog too for xkcd?
Also, randal is a complete genious.

@jl2, polkit allows you to configure yourself into a CVE, too tongue

Good to know tongue thanks

Last edited by jl2 (2025-04-27 06:32:19)


Why I run Arch? To "BTW I run Arch" the guy one grade younger.
And to let my siblings and cousins laugh at Arsch Linux...

Offline

#11 2025-04-27 06:38:21

seth
Member
Registered: 2012-09-03
Posts: 63,247

Re: [SOLVED] Alias systemctl

No, but there's a blag.
I don't know who that randal is, but Randall is certainly on the list I've submitted to Apophis to keep around if he doesn't want to get whacked again.

Offline

#12 2025-04-27 07:39:32

jl2
Member
From: 47° 18' N 8° 34' E
Registered: 2022-06-01
Posts: 678
Website

Re: [SOLVED] Alias systemctl

seth wrote:

No, but there's a blag.
I don't know who that randal is, but Randall is certainly on the list I've submitted to Apophis to keep around if he doesn't want to get whacked again.

Sogar die Gross/Kleinschreibung falsch roll (meine grösste Deutsch-Grammatik-Schwäche, wird mir immer mal wieder zum Verhängnis)

That exceeds my very limited ancient egyptan knowledge and the capacity to read Wikipedia ...
(Only found a image of Seth stabing him, is it a reference to that? [Even though everybody seemed to bash him in some way] Also, if Apophis was the god of darkness, was he the god of death too?)

Edit: I'm steering far into the offtopic part once again, feel free to steer back ...

Edit2: fixed english capitalisation smile

Last edited by jl2 (2025-04-27 07:52:46)


Why I run Arch? To "BTW I run Arch" the guy one grade younger.
And to let my siblings and cousins laugh at Arsch Linux...

Offline

#13 2025-04-27 10:03:32

seth
Member
Registered: 2012-09-03
Posts: 63,247

Re: [SOLVED] Alias systemctl

Apophis is not so much a god "of" - he *is* darkness, chaos and death.
And yes, the famous episode is where was about to tank the sunbark and everyone started to panic and freeze, so I rolled my eyes, picked my spear and whacked him over the head so the sun could rise again.
I btw. do that every night, you're welcome tongue

Offline

#14 2025-04-27 10:10:36

jl2
Member
From: 47° 18' N 8° 34' E
Registered: 2022-06-01
Posts: 678
Website

Re: [SOLVED] Alias systemctl

seth wrote:

I btw. do that every night, you're welcome tongue

Thank you for your service lol

The egyptains must really have hated snakes.

Anyway, you pulled out the most german way of saying something between "He's awesome" and "He's the absolute fucking goat". (He would've said "nicht schlecht" if he thought he was less than that lol)

Last edited by jl2 (2025-04-27 11:42:43)


Why I run Arch? To "BTW I run Arch" the guy one grade younger.
And to let my siblings and cousins laugh at Arsch Linux...

Offline

#15 2025-05-02 20:06:58

notadaughter
Member
Registered: 2024-04-08
Posts: 14

Re: [SOLVED] Alias systemctl

after multiple attempts aliasing systemctl in .bashrc, i came up with the following:

exec /usr/bin/systemctl "$@"

put this under /usr/local/bin/sc

this allows running both `sudo sc ...` and `sc ...`

Offline

Board footer

Powered by FluxBB