Right after my login session, I would like Ubuntu to execute sudo apt-get update & apt-get dist-upgrade
, systematically / automatically. The terminal must be opened so that I can see the output of each of these executions. In particular, I want to be asked to type "y/n" due to the command apt-get dist-upgrade
. I don't want to have to type my password : thus, Ubuntu must use it as input of the sudo
execution instead of me.
The modifications involved must be independant of any upgrade and migration of Ubuntu.
Question
Which bash
file should I edit and in which way ?
Sudo without password
You can tell sudo to let you execute commands without a password.
per the most upvoted answer here
You can also make it only allow apt to work without a password for just one user, and just for apt by adding this instead of the above:
replacing "username" with your username. You may have to reboot for these changes to take effect.
I would highly recommend using the single user/app solution as this will be much more secure than allowing complete use off sudo without a password for all sudoers... This could be a SERIOUS security issue, esspecially if someone gained physical access to your computer. In general, if this computer contains sensitive data, you will want to forgo any kind of passwordless sudoing.
Run command on startup
OR
~/.profile
The following command will open a terminal and run update:
Name and comment (gui) as you wish and save it. Now when you log in, a terminal will open and run your upgrade commands. You will not need to enter a password, but you will have to confirm the upgrade.
The window will then stay open until you press enter.
Now that you have this, you might want to go to
Software & Updates
and disable automatic checking for updates since this new script does it for you.This is easy enough, although I like to know what updates are applied so I prefer having the final say manually.
Anyway, the essential bit you need to know is how to run a
sudo
command from a script. That can be done using:or with the longer explicit but equivalent version
where
password
is your password, of course and the argument to-u
is the user which is root in this case.Then, note that your
.profile
bash script is run on logins. So in short, append the following commands to your.profile
:where the
-y
flag toapt-get
means answer yes to all questions. Your.profile
should have been created when your account was made, but in case it's been deleted, you can copy the default from/etc/skel/.profile
.Finally, for security, you will probably want to
chmod 600 .profile
to protect your password.