change password of other user using ssh
There are two servers in LAN. There are number of users in both servers.
I am user of one server. If I want to change password of another user of my server (I have these privileges by root), I can do it easily. But If I want to change password of other server's user, I use ssh. I log into other server using ssh and I use sudo passwd username. It asks me new password for the username and I can change it easily. But i have to do this thing multiple times. i want to use shell script for this. I have tried some combinations but it is not working. I want when I will run the shell script, it should ask me "new password" that I will enter and "retype password" that I will enter again and password will be changed. I don't want to login manually through ssh and manually enter the command "sudo passwd username" My shell scripts which are not working:- Code:
#!/bin/bash Code:
#!/bin/bash Code:
#!/bin/bash |
The problem is that passwd needs you to type it in to the programme itself. Try using the 'chpasswd' command.
(also, it's probably best not to use Code:
echo user:pass | chpasswd Code:
chpasswd < pwd_file |
You said
you are using `ssh server-IP` and it asks for password. It means you are logged in as root or may be your user has root privileges in /etc/passwd file because if you would be user, you would use `ssh username@server-IP` I am not giving you lecture here but I want to say if you do not know essential server administration you could harm your server. For your solution, Do not use sudo in shell script. May be your server will be RPM that's why you are facing this problem. My possible solutions are #!/bin/bash ssh server-IP passwd username OR #!/bin/bash ssh server-IP "passwd username" If you remove sudo into your shell script, they will work. Now it will ask, server's password and new & retype password for requested user. If you do not want that it should ask server's password again and again. Make authorized_keys file in server's ssh directory and put the content of your public file(.ssh/id_dsa.pub or .ssh/id_rsa.pub) into authorized_keys file. |
Oh, good reading, pavi_kanetkar... I completely misunderstood the question.
http://linuxproblem.org/art_9.html describes what pavi_kanetkar was talking about in his last paragraph. |
@pavi
Thanks for your solution, Now it is working. I removed word 'sudo' into my shell scripts and most of them are working in the way I want. Now when I run my shell script in terminal using "./shell-script-name.sh" or "sh shell-script-name.sh" First it asks for server's password, then I enter it. Now it asks for user's new password, I entered it too. Now retype password and after this the username defined in shell script whose password is changed. That's what I wanted. |
Brilliant, in that case please mark the thread as 'SOLVED' and give pavi some reputation (click on 'Yes' next to 'Did you find this post helpful?' on his post)
|
All times are GMT -5. The time now is 07:55 AM. |