1

I am on Debian 11 testing. It's a low-end computer intended for users with little computer experience and I want to keep it up to date with a script that do not prompt users for a password.

Following the advice of several topics (like here):

So I wrote a simple script /home/user/Documents/update.sh like this:

#!/bin/bash
sudo apt update -y
sudo apt upgrade -y
sudo apt autoclean -y
sudo apt autoremove -y

I then make the script executable:

chmod a+x /home/user/Documents/update.sh

Then I gave the user user the rights with visudo so as not to ask for the password

user ALL=(ALL:ALL) NOPASSWD:/home/user/Documents/update.sh, /usr/bin/apt update, /usr/bin/apt upgrade, /usr/bin/apt autoclean, /usr/bin/apt autoremove

After testing by running the command on the terminal sh '/home/user/Documents/update.sh', the script works without asking me for a password.

To run the script at each startup, I modify crontab -u user -e (I also tested directly with crontab -e):

@reboot sh '/home/user/Documents/update.sh'

But on each reboot: no script starts.

As an alternative I try to make an update.desktop file in /usr/share/applications in which a double-click starts the script:

[Desktop Entry]
Name=update
Exec=sh '/home/user/Documents/update.sh'
Terminal=true
Type=Application
Encoding=UTF-8

After testing, double-clicking on this file runs the script without asking for a password

Then, with Gnome Tweaks, I add the file updates.desktop as an application at startup

This is where my second problem comes in: the script starts at startup, but asks me for a password.

Then I don't understand why this happens (is Gnome Tweaks running under another user, etc.).

  1. Why the crontab method does not work ? (I already have started crontab service to be sure)
  2. Why the Gnome Tweak method prompt me for a password ?
David Makogon
  • 69,407
  • 21
  • 141
  • 189
prog-amateur
  • 121
  • 1
  • 7

0 Answers0