Set password in single command


 
Thread Tools Search this Thread
Operating Systems Linux Set password in single command
# 1  
Old 12-02-2010
Set password in single command

Hi,
Can we set password for linux in non-interactive mode.
I didn't find suitable option for this in man page.
If we wnter "passwd" command, it will tell "Enter password" and "Re-enter password". i wanted to run this step in a script, and i don't want to use "expect" so i am looking for a single command to set password.
# 2  
Old 12-02-2010
Hi.

Do you have chpasswd installed?.

Code:
# yum whatprovides /usr/sbin/chpasswd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror.switch.ch
 * base: mirror.switch.ch
 * extras: mirror.switch.ch
 * updates: mirrors.supportex.net
2:shadow-utils-4.0.17-15.el5.x86_64 : Utilities for managing accounts and shadow password files.
Repo        : base
Matched from:
Filename    : /usr/sbin/chpasswd



2:shadow-utils-4.0.17-14.el5.x86_64 : Utilities for managing accounts and shadow password files.
Repo        : installed
Matched from:
Other       : Provides-match: /usr/sbin/chpasswd

This User Gave Thanks to Scott For This Post:
# 3  
Old 12-02-2010
If it doesn't matter if it is set to a known password you could overwrite the second field of the shadow file with a known hash.
# 4  
Old 12-02-2010
chpasswd also expects some user input, i wanted a way to set password in non-interactive way.
Is this posible?
# 5  
Old 12-02-2010
I would read the man page (or read it again if you already have Smilie)

chpasswd(8)

Code:
$ chpasswd -c < file_with_passwords

where file_with_passwords contains user-password pairs:
Code:
$ cat file_with_passwords
user1:password1
user2:password2

or
Code:
echo user1:password1 | chpasswd -c

# 6  
Old 12-02-2010
/usr/sbin/chpasswd -c < t
/usr/sbin/chpasswd: invalid option -- c
Usage: chpasswd [options]

I think "-c" option is not there.

in the above command, t is the file having user:password
# 7  
Old 12-02-2010
Oh yes, -c is an option on AIX chpasswd. Maybe I should have read that man page myself Smilie

Then leave it off, or find a Linux equivalent.

In AIX it means:
Quote:
-c Clears all password flags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need one line command to create and set password for new user...

Using useradd abc --password password (5 Replies)
Discussion started by: Jagruti Rml
5 Replies

2. Solaris

Not able to set password

I have a Solaris-10 non global zone, on which I am not able to reset password, while counts are matching in /etc/passwd and /etc/shadow. I tried searching its solution in various forums, but nothing is working # id -a oemagent uid=56605(oemagent) gid=56595(tess) groups=56595(tess) # passwd -s... (2 Replies)
Discussion started by: solaris_1977
2 Replies

3. Shell Programming and Scripting

Script to set password in HP-UX 11.31

Hi, I am unable to set the password remotely. I am using the script as below: ep=`echo "$p" | /usr/lbin/makekey` ssh -t $i "/usr/local/bin/sudo useradd -c "$user_c" -m -d /home/$user_id -s /bin/ksh $user_id; /usr/local/bin/sudo /usr/sam/lbin/usermod.sam -F -p $ep $user_id" The... (0 Replies)
Discussion started by: Kits
0 Replies

4. AIX

How to set 4 SEA on single VIOS

Hi experts, i got a 4-port Adapter card on VIOS and would like to configure 4SEA for 4 difference segment IP client's LPAR use, first SEA succeed to be configured on ent0 but once second SEA configured, first SEA fail to be connected. Any issues i need to be concerned in order to configure 4 SEA on... (8 Replies)
Discussion started by: polar
8 Replies

5. Shell Programming and Scripting

How to give user name and password in a single command to login to remote server

Hello All, I'm new to unix and i need the below favour from you. I have list of 50 unix server. I need to login to all the server one by one and with the same user and password. I will declare the user name and password globally in the script. for example : servername- hyperV user name... (4 Replies)
Discussion started by: Hari A
4 Replies

6. AIX

Single user mode password

Hi, How to check whether the single user mode is password protected or not?By default, while entering in to single user mode, Os is not asking for login credentails. How can i enable it. Kindly help Rgds, kmvinay (2 Replies)
Discussion started by: kmvinay
2 Replies

7. HP-UX

Single quotes contained within a password

Are single quotes allowed in a UNIX password? With my understanding that UNIX interprets single quotes in pairs and has a distinct meaning to the shell that it removes special meaning of all enclosed characters. I wanted to confirm that a single quote within a password would fail for this reason. (4 Replies)
Discussion started by: roni13
4 Replies

8. Solaris

Not able to (re)set the Password

I have installed Solaris 10 x86 in VMware 5.5.I logged in as root user and trying to create new user and also reset the password for existing user, i am getting "Permission Denied Error". I checked the /etc/shadow file, looks fine permission is 400. Earlier i was able to do it but suddenly it... (2 Replies)
Discussion started by: khagendra
2 Replies

9. UNIX for Dummies Questions & Answers

Can we set it so people can't use the same password twice?

If we have it so users accounts need a new password after 90 days is there a way to also say that after 90 days they need to use a new password and not let them use the same one twice? (2 Replies)
Discussion started by: LordJezo
2 Replies

10. UNIX for Dummies Questions & Answers

Single line password reset.

Hi, I need to know if this command echo NEWPASSWORD | passwd --stdin USERNAME that works fine on Red Hat Linux, is also available on other Unix/Linux machines (AIX, FreeBSD, OpenBSD, SunOS, Mandrake, Debian, Gentoo, Lindows, Slackware, Xandros, HP-UX, IRIX, SCO, MacOS, BSDi ...). ... (2 Replies)
Discussion started by: margi973
2 Replies
Login or Register to Ask a Question