Solaris Troubleshooting NIS: add a user for NIS maps when passwd file is not in the /etc directory
Below procedure can be used to add a new NIS user when the passwd file is not in the /etc directory
Steps to Follow
The example below demonstrates how to add a user for NIS maps when the passwd file is not in the /etc directory.
The NIS directory is /etc/nisdir, where all the NIS maps reside.
Create a user in the /etc/passwd file. In this example, the new user is Johnl
Step 1.
Edit /etc/passwd to Add entry for the user
# vi /etc/passwd
Johnl:x:107:14:John l:/export/home/johnl:/bin/csh
Assign a password to the new user.
passwd johnl
Step 2:
Now run below command to create an entry in the shadow file
# pwconv
cat /etc/shadow file to see this entry in there.
johnl:dhXRywfkSELcE:10091::::::
Step 3:
Just copy the new entries to the /etc/nisdir/passwd file for passwd entry, and /etc/nisdir/shadow for shadow entry. To update the passwd map and push it to the slaves.
# make passwd
**NOTE**If you do not want this new user to be a local user, delete the entries in /etc/passwd and /etc/shadow.
Hello dear
its good but not clear copy which entry to which file like from passwd to which file and from shadow to which file or only one entry is sufficient
Hello Sukhbir.
entry “Johnl:x:107:14:John l:/export/home/afzal:/bin/csh” from /etc/passwd to /etc/nisdir/passwd and entry “johnl:dhXRywfkSELcE:10091::::::” from /etc/shadow to /etc/nisdir/shadow.
hope this helps
Thanks Ram
its now clear
Thnx a lot
Have a good day……….
why pwconv here
@ravi, Since we added the new user by manually editing the /etc/passwd, we want to get the corresponding entries in /etc/shadow with pwconv command. Alternatively we can edit the /etc/shadow for the entries without using the pwconv.
Thats a very messy way , take a look at Perl an Unix::PasswordFile modules :
heres my password reset scripts for an example :
#!/usr/bin/perl -w
use Unix::PasswdFile;
my $PASSWORDFILE = “/var/yp/src/passwd”;
use strict;
unless (@ARGV >= 1)
{
print “nBetter if you supply a username !n”;
exit ;
}
# now generate the random password and get the forgetful user name
chomp(my $ranpass= `/usr/sfw/bin/openssl rand -base64 6`);
chomp(my $user= shift);
#open the password file
my $pw = new Unix::PasswdFile $PASSWORDFILE;
if (!defined $pw->user($user))
{
print “n try to supply a valid username …. moronn”;
print “n now we are all laughing at you .hahahaha n”;
exit ;
}
$pw->passwd($user,$pw->encpass($ranpass));
$pw->commit() or die “cant commit passwd files changes :$1”;
# Rebuild NIS maps
print “nBuilding NIS maps…n”;
system(“cd /var/yp && /usr/ccs/bin/make”);
print “nn————— CUT and SEND to USER ———-n”;
print “Your password has been resetn”;
print “Username: $usern”;
print “Password: $ranpassn”;
print “n ——————–END CUT ——————-n”;
Thanks Gavin for providing the script, really appreciate your time.