SU Topics | Previous | Next

Avoiding Password Prompting With SU


You can redirect a password to avoid prompting, providing that STDIN (standard input) is redirected accordingly. If SU is running under a command processor, the following approaches are suitable for redirecting a password:

su username < c:\password\username.txt

The password for user username is obtained from c:\password\username.txt. The password must be followed by a carriage return in the file username.txt. On NTFS file systems, you can apply security to username.txt such that only the callers of SU have access to the password file or directory.

echo mypassword | su username

Password mypassword for user username is piped to SU. This approach is useful for batch files. Note that on NTFS file systems, the batch file executing this command should have security applied such that only the callers of SU have access to the batch file. Note also that some command processors might not handle this case properly.

In addition, you can avoid password prompting by setting the environment variable SU_PASSWORD in the process or batch file that launches SU. This environment variable is used only when the SU graphical user interface (GUI) is not invoked.