Ubuntu – Password for apps


I want to limit access to running apps with a password. Is that possible?
I have an app in the tray icon and I want to close it for unauthorized access.


Best Answer

  • The following setup is fit for "home, garden and kitchen" use, when no specific security is needed. I also need to say that it is still possible to open the application via the command line; it is strictly for "indoor" use, to prevent children to acces an application for example.

    The trick is to redirect the command in the application's desktop file to a script that calls the application, provided that the right password is given.The setup can be undone easily.

    Below are two scripts, one to call the window to enter the password (script1), and one to process the given password (script2).

    Prepare the scripts:

    script1, call the zenity window to enter the password:

    if zenity --entry \
    --title="Restricted!" \
    --text="Enter your _password:" \
    --entry-text "password" \
      then echo $?
      else echo "No password entered"

    Copy the text above, paste it in an empty document, save it in ~/ as "passwordwindow", and make it executable.

    script2 to process the given password:

    import subprocess
    # application_name = the command to start the application:
    application_name = "application_name"
    # enter the required password here:
    password = "password"
    # enter the path to script1 here (for example ~/passwordwindow):
    path_to_script1 = "path_to_script1"
    getpassword = subprocess.Popen([path_to_script1], stdout=subprocess.PIPE)
    passwordinput = getpassword.communicate()[0].decode("utf-8").replace("\n0\n", "")
    if passwordinput == password:

    Copy the text above, paste it in an empty document and replace the following entries in the headsection of the script:

    • replace in the script the "application_name" by the command to open the application. If you don't know, open the application's desktop file, located in /usr/share/applications, with gedit and copy what comes after "Exec=".
    • replace "password" by the required password.
    • replace "path_to_script1" by the real path to script1 (e.g. "/home/yourname/passwordwindow").

    include the quotations.

    Save the file (hidden) as .myownpassword.py in ~/

    Prepare the .desktop file:

    To finish the setup:

    • copy the application's desktop file from /usr/share/applications to~/.local/share/applications`
    • open the file with gedit and replace the command after "Exec=" by: python3 /path_to_script2/.myownpassword.py (no quotation)

    Now, after next log out / login, if you start the application, you will be asked for your password, as defined in script2:

    enter image description here

    How to remove:

    To undo the setup, just remove the local desktop file in /.local/share/applications and the two scripts in your ~/ directory.

  • Related Question