Bobcares

Set SUDO_ASKPASS Variable in Ubuntu

PDF Header PDF Footer

Learn how to set the SUDO_ASKPASS Variable in Ubuntu. Our Server Management Support team is here to help you with your questions and concerns.

Set SUDO_ASKPASS Variable in Ubuntu

When we work with the Linux command-line utility sudo, sometimes we need to input our password non-interactively. This is when the SUDO_ASKPASS environment variable comes in handy. It tells sudo which program to use when it needs to prompt for a password without user interaction.

Set SUDO_ASKPASS Variable in Ubuntu

This is useful while running commands via graphical applications that do not have a terminal for password entry. Today, we will take a look at how to set up and use the SUDO_ASKPASS variable.

The SUDO_ASKPASS variable can be set via two methods.

Method 1: Setting the Environment Variable

  1. First, open a terminal.
  2. Then, run this command:
    export SUDO_ASKPASS=/usr/bin/ssh-askpassCopy Code

    Here, export is a shell builtin. It sets SUDO_ASKPASS to the value /usr/bin/ssh-askpass. In fact, this value is the path to the ssh-askpass program. This is a common askpass program for Ubuntu. If our program is located in a different location, we have to mention it here.

    Furthermore, we can make this change take effect across logins, by adding the export command to our ~/.bashrc file.

Method 2: Modifying the sudo.conf File

  1. First, open a terminal.
  2. Then, run this command:
    sudo nano /etc/sudo.confCopy Code
  3. Next, we have to uncomment the line for the askpass program by removing the # at the beginning of the line.
  4. Now, we have to save the file and exit.

The above steps will apply the change system-wide and persist across logins.

How to test the SUDO_ASKPASS Variable

After setting the SUDO_ASKPASS variable, we can test it by running a command with sudo -A:

SUDO_ASKPASS=/usr/bin/ssh-askpass sudo -A idCopy Code

It prompts us for our password with the askpass program specified and then executes the id command with elevated privileges.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to set the SUDO_ASKPASS Variable in Ubuntu.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!