In order to prevent someone (other than me) from changing my background, how can I make wallpaper changing an action requiring a password?
-
Is this helping you? http://askubuntu.com/a/445184/72216 – Jacob Vlijm Sep 30 '14 at 06:16
-
See Jacob's comment. You will most likely not be able to block background changing, but you can definitely protect
. – Kaz Wolfe Sep 30 '14 at 06:30 -
I don't really know the command to change wallpapers. My shellscripting skills aren't the best but if you give me the path. – rajlego Oct 01 '14 at 15:20
-
@Whaaaaaat See comment – rajlego Oct 02 '14 at 12:33
-
@JacobVlijm See comment – rajlego Oct 02 '14 at 12:34
-
Is this post of any help? http://askubuntu.com/a/527633/72216 both commands to get the current/set another wallpaper are in the script (cmd1 / cmd2) – Jacob Vlijm Oct 02 '14 at 16:38
-
@JacobVlijm Thanks that worked for me. I guess this question us a duplicate, should I delete it? – rajlego Oct 05 '14 at 18:19
-
@rajlego The question has been mentioned too broad, but not a duplicate as far as I can see. If it is specifically the wallpaper, then probably. If you can make your question more specific to one case? The wallpaper link is not asking for a password :) – Jacob Vlijm Oct 05 '14 at 18:25
-
possible duplicate of How can I block users to change wallpaper (under Unity in Ubuntu 12 and 14)? – muru Oct 06 '14 at 17:35
-
@muru I thought this question was a duplicate to, except for one difference: I want to be able to change the wallpaper if I want by typing in my password. If you think I'm wrong, please tell me, I will delete the question. But I did as Jacob if this was a duplicate already and I don't think it is based on his response. – rajlego Oct 07 '14 at 00:46
-
My flag was based on your comment that you "guess this question us a duplicate". If it isn't, sorry. – muru Oct 07 '14 at 00:48
-
@muru no problem, no harm done – rajlego Oct 07 '14 at 00:55
-
To the latest close-voter: how ever can this be too broad? – Jacob Vlijm Oct 08 '14 at 18:49
2 Answers
Password protect changing wallpaper
The script below provides a mild password protection for changing the wallpaper in "home" situations. Mild because the password is stored inside the script in plain text. Nevertheless it should prevent average users from changing the wallpaper.
What it does is that when a user changes the wallpaper, it changes back immediately, and the user is prompted for a password. If the password is correct, the wallpaper changes into the newly set one, otherwise nothing happens.
To minimize the risk, store the script in an unexpected place under an unexpected name, and /or as a hidden file.
To use it:
Copy the script below into an empty file, set a password of your choice in the head section (I wouldn't choose your sudo password for security reasons, since it is in plain text!) and save it as name.py
, run it by the command:
python3 /path/to/name.py
The script:
#!/usr/bin/env python3
import time
import subprocess
set_password = "monkey"
key = "org.gnome.desktop.background picture-uri "
read = "gsettings get "+key; change = "gsettings set "+key
set_wallpaper = subprocess.check_output(["/bin/bash", "-c", read]).decode("utf-8").strip()
pass_window ='zenity --entry --entry-text="Enter password" --text="Enter password" --title="password" --hide-text'
def check_wall():
global set_wallpaper
curr_wallpaper = subprocess.check_output(["/bin/bash", "-c", read]).decode("utf-8").strip()
if curr_wallpaper != set_wallpaper:
subprocess.Popen(["/bin/bash", "-c", change+set_wallpaper])
try:
entered_password = subprocess.check_output(
["/bin/bash", "-c", pass_window]).decode("utf-8").strip()
except Exception:
entered_password = None
if entered_password == set_password:
subprocess.Popen(["/bin/bash", "-c", change+curr_wallpaper])
set_wallpaper = curr_wallpaper
else:
pass
while True:
check_wall()
time.sleep(3)
posted on gist.gisthub

- 83,767
-
Why not add a script to change owner of gsettings to root after boot, and share the user and root password. It won't need an infinite loop. – xyz Oct 08 '14 at 19:06
-
@prakharsingh95 Although I did try something like that (but it didn't work somehow), in general I prefer to keep the existing configuration and permissions untouched. I chose for a relatively simple script that could be started and stopped on the fly. If you can make it work however, it would be a nice additional answer to this question. – Jacob Vlijm Oct 08 '14 at 19:20
This turned out to be a nice challenge. Try,
$ sudo mv /usr/bin/gsettings /usr/bin/gsettings2
$ sudo gedit /usr/bin/gsettings
$ sudo chmod +x /usr/bin/gsettings
When gedit comes up on the second instruction, add:
#!/bin/bash
if [ "$1" == "set" ] && [ "$2" == "org.gnome.desktop.background" ] && [ "$3" == "picture-uri" ]; then
a=$(zenity --entry="Password")
h1=$(/bin/echo $a | /usr/bin/md5sum | /bin/cut -f1 -d" ")
h2='a799d7cf3d9ca647f1320fc6bfaf7408' #Password hash
if [ "$h1" == "$h2" ]; then
gsettings2 set org.gnome.desktop.background picture-uri $4
else
zenity --notification --text="Wrong password. Come again another day"
fi
else
$(gsettings2 $@)
fi
To undo,
$ sudo rm /usr/bin/gsettings
$ sudo mv /usr/bin/gsettings2 /usr/bin/gsettings
You can go to this md5 generator, put your string and replace a799d7cf3d9ca647f1320fc6bfaf7408
with whatever you like. Try finding out for yourself what this corresponds. You'll realize how secure this is.
Even if somebody views this file, without your password they cannot change it (This is similar to how linux stores your passwords :P).

- 1,786
- 1
- 12
- 22