How to set password for users in AIX using single line command?
You can use chpasswd
The chpasswd command administers users' passwords. The root user can supply or change users' passwords specified through standard input. Each line of input must be of the following format.
username:password Only root users can set passwords with this command.
Example 1:
echo username:password | chpasswd
Example 2:
Also for security you can pass encrypted password to chpasswd
# Create Password in Encrpyted Form Using below command
# perl -e'print crypt("YourPassword", "salt")' ; echo -e
echo username:cryptedPass | chpasswd -e
Related videos on Youtube
atp9
Updated on September 18, 2022Comments
-
atp9 almost 2 years
Is there any way in which I can set the password for a newly created user account in AIX in a one line command? I don't want to give any prompt to the user. If there is a command, it should set the password to that user without asking anything on the screen. I need to use that command in another technology like Java/.Net. I need to create the accounts with password on a AIX machine at run time by executing one line of code where I can pass parameters. Suppose a user is giving a username in the text box of a Java application and in the background the command needs to be executed which will create the user accounts(with the password) at a remote AIX server. I am successful to add a user account, but setting the password is something where I am stuck.
-
Rahul Patil almost 11 years@tbp_09 can you please accept ans as correct :)
-
atp9 over 10 yearsAny idea how can I do the same thing for su command. Assume I have a root password and i want to change to root mode without giving any prompt so that i can run/invoke scripts from remote server using java or .net
-
Rahul Patil over 10 yearshave take look at expect tool nist.gov/el/msid/expect.cfm
-
Rahul Patil over 10 yearsalso check some su trick in this link vladz.devzero.fr/002_su-stdin.php
-
atp9 over 10 yearsThanks for suggesting vladz.devzero.fr/002_su-stdin.php I can try something like that.
-
atp9 over 10 yearsI tried expect command but it is not helping me to understand how it will work. what i am trying is as below: #!/usr/bin/expect su expect "Password:" send "xyz"
-
atp9 over 10 yearsMy understanding on this command is that when it hits su command (it may get in waiting status) and expect command reads Password from su prompt and it will send my password (xyz) to the prompt. here the problem is i am getting error:invalid command name "su" while executing "su" (file "testSample1.sh" line 2)
-
Rahul Patil over 10 years
-
atp9 over 10 yearsThanks for that link Rahul. That works if i have spawn command. I need to run that on AIX and it gives me an error "spawn not found".
-
Rahul Patil over 10 yearscan you please show me screen shot of that error, if possible show me your script also
-
atp9 over 10 yearsI have added a screen shot with question. Please let me know what is wrong here. Well i couldn't find any other place to add it so thought to add that in question itself
-
atp9 over 10 yearsearlier I used to get spawn not found error but now something new came up. it shows line of code and nothing happens. I have root password using which I am creating the new account but no luck in that.
-
Rahul Patil over 10 yearsshow the code,talk is less
-
atp9 over 10 yearsI have added that to question. as image
-
Rahul Patil over 10 yearsMysu.sh should contains only
/usr/bin/su -
-
Rahul Patil over 10 yearsthen in same script use
send useradd testuser2