Linux – Hide arguments of commands in ps

argumentscommandlinuxprocessps

I run an application on a linux server, and when I run the application I supply the password as a command line, like this:

 ./myapplication --smtp-password mypassword

In our application, we didn't built so far encrypt/decrypt , because it is supposed to be a very simple monitoring application, and it is very simple "pinging" and health check and send email in case of failure.

Any admin – and we have three other admins – can just list the process with ps, and see the command arguments, and figure out the password.

Is there a way to hide that?

Best Answer

Better would be to rewrite myapplication so it gets the password via some other mean like stdin. The environ is another option, but that is still visible to processes with the same euid (or euid 0) via /proc/<pid>/environ.

If not, on Linux with versions prior to 4.2, you can limit the exposure by making sure the password is not in the first 4096 bytes of the command line so other processes can't obtain it via reading /proc/<pid>/cmdline (like ps does). 4.2 and above no longer truncate /proc/<pid>/cmdline.

For instance, with zsh

.${(l:4094::/:):-myapplication} --smtp-password=secret

Would run myapplication with the first argument being 4095 bytes large (4096 you'd trip the PATH_MAX limit), something like .//////[...]///myapplication, so your password would be beyond the 4095 break point.

Note that audit logs and shell history files are other areas of concern for secret strings passed on the command line.

Related Question