Um, you have to be root to be able to do anything with
/etc/shadow, so why not simply use
passwd?
Code:
passwd user_name < this lets root change it
passwd -l user_name < this lock it (sticks an '!' in the password field)
passwd -d user_name < this delete the password
There are other options, see
man passwd (as root).
If you really want to fiddle around with
/etc/shadow, carefully, carefully, you have to be root and you can simply edit it with
vi; thus, if you can generate a legit hash and you're root, you can simply edit that into the password field.
Here's a little C program that will generate a hash:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <time.h>
#define _XOPEN_SOURCE
#include <unistd.h>
extern char *crypt (const char *, const char *);
void main (int argc, char *argv [])
{
char salt [3];
char *passwd, *encryptedpw;
char *user;
int i;
/* seed the random number generator */
srand ((int) time ((unsigned int) NULL));
/*
* we need two random numbers in the range
* >= 65 <= 90 or >= 97 <= 122 (that's A - Z
* or a - z inclusive) for the salt characters
*/
while ((i = rand()) < 65 ||
i > 90 && i < 97 ||
i > 122)
;
salt [0] = i;
while ((i = rand()) < 65 ||
i > 90 && i < 97 ||
i > 122)
;
salt [1] = i;
salt [2] = '\0';
/* find out who we are */
if ((user = getenv ("USER")) == (char *) NULL) {
(void) fprintf (stderr,
"%s:\tunable to determine user id\n",
argv [0]);
exit (EXIT_FAILURE);
}
/* ask for the password */
passwd = getpass ("Password to encrypt: ");
/* crypt() only looks at the first two characters of salt */
encryptedpw = crypt (passwd, salt);
(void) fprintf (stdout, "%s:%s\n", user, encryptedpw);
exit (EXIT_SUCCESS);
}
Save the above in some "file.c" then
Code:
cc -o file file.c -lcrypt
Use at your own risk.
Hope this helps some.