I am making a script that will update my system (and do some other things, but that doesn't matter). I want the script to run sudo apt-get update
and sudo apt-get dist-upgrade --yes
automatically. I use --yes so I won't have to choose yes when it runs; it upgrades all packages automatically without me having to do anything. That said, I want to put my password in the script somehow so I won't have to type in my password when I run it either, probably with an argument or something. You know, something I can put at the end like sudo apt-get update --passwd MYPASSWORDHERE
. I have tried that and it doesn't work, but that's an example of what I want. What argument (--passwd or --password or something) do I put at the end to do this?
Asked
Active
Viewed 1,955 times
1

John Scott
- 1,462
- 7
- 24
- 48
-
possible duplicate of How do I enable automatic updates? – Panther Jul 10 '14 at 21:19
-
See also http://askubuntu.com/questions/307067/how-to-execute-sudo-commands-with-expect-send-commands-in-bash-script – Panther Jul 10 '14 at 21:19
-
This is a duplicate and there are several options open to you. – Panther Jul 10 '14 at 21:20
-
This has nothing to do with updating my system; I just want to know how to have the password put in automatically when using sudo in a script. – John Scott Jul 10 '14 at 21:20
-
I meant about you saying it was a duplicate in your first comment; not your second comment. :P – John Scott Jul 11 '14 at 00:34
2 Answers
1
Sudo doesn't behave that way, for security reasons. You can echo the password to sudo using the -s option, but I don't suggest it. Even if you protect your script from other users, they can still see your parameters using e.g. ps -ef
.
I think your problem is better solved by installing the unattended-upgrades package.

Sophit
- 296
- 1
- 8