https://github.com/remram44/read-sudo-timestamp
Read sudo's files to check for a valid timestamp, for use in shell prompts
https://github.com/remram44/read-sudo-timestamp
linux linux-shell shell-prompt sudo unix
Last synced: 6 months ago
JSON representation
Read sudo's files to check for a valid timestamp, for use in shell prompts
- Host: GitHub
- URL: https://github.com/remram44/read-sudo-timestamp
- Owner: remram44
- License: mit
- Created: 2023-02-06T03:44:08.000Z (over 2 years ago)
- Default Branch: trunk
- Last Pushed: 2023-02-07T02:22:02.000Z (over 2 years ago)
- Last Synced: 2025-03-28T21:11:18.731Z (6 months ago)
- Topics: linux, linux-shell, shell-prompt, sudo, unix
- Language: C
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is a simple utility that reads sudo's timestamp file to figure out whether you have a valid timestamp.
This allows you to show a warning in your prompt if your shell currently allows you to run commands with sudo without a password.
# How to use
Build this executable with `make`, then install it with `sudo make install`. This will make it set-uid root so it can read sudo's timestamp files.
You can then put something like this in your shell's config file (example for bashrc):
```bash
PS1='`if read_sudo_timestamp 900 >/dev/null; then echo "SUDO "; fi`\u@\h:\w\$ '
````900` in the code above is sudo's timeout in seconds. I didn't try to get it from sudo's configuration file, it is easy enough for you to supply.
# Is a separate program really required?
Unfortunately sudo never provided a way to do this. On some versions you can abuse `sudo -v` to check whether there is a valid timestamp, however this counts as a failed login on some versions, sending the admin an email every time (thousands of emails if you have this in your prompt...), [sudo#131](https://github.com/sudo-project/sudo/issues/131). Additionally this would refresh the timestamp every time instead of only checking it.
The sudo project has been asked for a solution but refused, see [sudo#130](https://github.com/sudo-project/sudo/issues/130), so writing a separate program seemed the easiest way.