Changing an AIX password via script?

2020-02-16 11:58发布

I am trying to change a password of a user via script. I cannot use sudo as there is a feature that requires the user to change the password again if another user changes their password.

AIX is running on the system.

unfortunately, chpasswd is unavailable.

I have expected installed, but I am having trouble with that also.

here is what I thought would work

echo "oldpassword\nnewpasswd123\nnewpasswd123" | passwd user

However once run the script I am prompted with please enter user's old password shouldn't they all be echoed in?

I am a beginner with shell scripting and this has been baffled.

13条回答
闹够了就滚
2楼-- · 2020-02-16 12:30

If you can use ansible, and set the sudo rights in it, then you can easily use this script. If you're wanting to script something like this, it means you need to do it on more than one system. Therefore, you should try to automate that as well.

查看更多
叼着烟拽天下
3楼-- · 2020-02-16 12:31

You need echo -e for the newline characters to take affect

you wrote

echo "oldpassword\nnewpasswd123\nnewpasswd123" | passwd user

you should try

echo -e "oldpassword\nnewpasswd123\nnewpasswd123" | passwd user

more than likely, you will not need the oldpassword\n portion of that command, you should just need the two new passwords. Don't forget to use single quotes around exclamation points!

echo -e "new"'!'"passwd123\nnew"'!'"passwd123" | passwd user
查看更多
疯言疯语
4楼-- · 2020-02-16 12:33
printf "oldpassword/nnewpassword/nnewpassword" | passwd user
查看更多
冷血范
5楼-- · 2020-02-16 12:35

You can try:

echo "USERNAME:NEWPASSWORD" | chpasswd

查看更多
走好不送
6楼-- · 2020-02-16 12:36

You can try :

echo -e "newpasswd123\nnnewpasswd123" | passwd user

查看更多
SAY GOODBYE
7楼-- · 2020-02-16 12:37
Here is the script... 

#!/bin/bash
echo "Please enter username:"
read username
echo "Please enter the new password:"
read -s password1
echo "Please repeat the new password:"
read -s password2

# Check both passwords match
if [ $password1 != $password2 ]; then
echo "Passwords do not match"
 exit    
fi

# Does User exist?
id $username &> /dev/null
if [ $? -eq 0 ]; then
echo "$username exists... changing password."
else
echo "$username does not exist - Password could not be updated for $username"; exit 
fi

# Change password
echo -e "$password1\n$password1" | passwd $username

Refer the link below as well...

http://www.putorius.net/2013/04/bash-script-to-change-users-password.html
查看更多
登录 后发表回答