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? askubuntu.com/a/445184/72216– Jacob VlijmSep 30, 2014 at 6:16
-
See Jacob's comment. You will most likely not be able to block background changing, but you can definitely protect <insert app name here>.– Kaz WolfeSep 30, 2014 at 6: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.– rajlegoOct 1, 2014 at 15:20
-
@Whaaaaaat See comment– rajlegoOct 2, 2014 at 12:33
-
@JacobVlijm See comment– rajlegoOct 2, 2014 at 12:34
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
-
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.– xyzOct 8, 2014 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. Oct 8, 2014 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).