I saw this question asked today, and thought I’d write a quick
post about it.
Giving passwords on the command line isn’t necessarily a
fantastic idea – but you can sort of see where they’re coming
from. Configuration files and environment variables are better,
but just slightly. Security is a night mare!
But if you do decide to write an application which takes a password (or any other sensitive information) on the command line, you can prevent other users on the system from easily seeing it like this:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
int main(int argc, char *argv[]){
int i = 0;
pid_t mypid = getpid();
if (argc == 1)
return 1;
printf("argc = %d and arguments are:\n", argc);
for (i ; i < argc ; i++)
printf("%d = %s\n" ,i, argv[i]);
…