How to see in the terminal that you have sudo privileges? (so knowing I have these privileges, I can just type sudo -k
) It would be better to not add too much information into the terminal also, just some kind of simple and small alert!
REMAINING TIME IS IMPOSSIBLE, right?
Also, how to see how much time I still have with those privileges on that specific terminal? (so I can just let it end instead of typing sudo -k
). I think that remaining time could show up each time I press Enter key.
EDIT: I researched more and found that /var/lib/sudo/$USER/$nPts
(where $nPts is current terminal pts as of ps -p $$
) has its timestamp updated everytime a sudo command is issued, and it is only accessible if you use a sudo command, so the remaining time will always be the configured one...
PS.: Alternatively to that, I tried alias sudo='sudo -k'
but I dislike having to type the password for every command... And also, this alias sudos='sudo -k'
(or alias ssudo='sudo -k'
, good if you typed a long line, just press Home and type 's') works if you only want to issue one command by typing sudos
. But I still miss to know when I have normal sudo privileges to know I need to act...
[I still would like to know if there is a better answear.]
I found a way that works, and the prompt will be kept on a single line:
at the end of your
~/.bashrc
add this:EDIT: I found that
sudo -n uptime
will update the sudo timeout, so everytime you hit the Enter key, that sudo time will be updated... That makes knowing the remaining time useless, as it will always be the configured one, defaulting to 15min...and to find the best colors formatting for you taste you can use ScriptEchoColor with
--escapedchars
option like:to just stop the blinking remove
\E[5m
like in\E[0m\E[93m\E[41m\E[1m SUDO \E[0m
Your terminal doesn't "have sudo privileges", unless you do something silly like
sudo bash
DON'T DO THIS!All you have to do to "have normal sudo privileges" is to refrain from typing
sudo
in front of the command./usr/bin/id
is a good way to see whatsudo
does. For example:The
sudo
man page says "The sudoers policy caches credentials for 15 minutes, unless overridden in sudoers(5)". What this means is that, by default, if you issue asudo
command (and enter your password),then wait 14.9 minutes before issuing a secondsudo
command, you won't have to enter your password again. If you wait 15.1 minutes, you will have to re-enter the password.sudo -k
simply expires the 15 minute timer immediately. The only use I can see forsudo -k
is if you're about to yield your unlocked terminal to someone you don't trust withUID 0
.