LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-04-2012, 06:58 AM   #1
bloodstreetboy
Member
 
Registered: May 2012
Posts: 198
Blog Entries: 3

Rep: Reputation: 37
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
ssh server-IP sudo passwd user
OR
#!/bin/bash
ssh server-IP 'sudo passwd user;'
It asks me server's password when I enter this, terminal disappears and nothing happens

Code:
#!/bin/bash
ssh server-IP ; sudo passwd user
OR
#!/bin/bash
ssh server-IP; sudo passwd user
It ends on server's command prompt and does not execute the change passwd command.

Code:
#!/bin/bash
ssh server-IP | sudo passwd user;
It is not working too. Please help
 
Old 09-04-2012, 07:13 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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
, if you were tempted to do that - create a file with user:pass in it and run
Code:
chpasswd < pwd_file
for security reasons)
 
Old 09-04-2012, 07:23 AM   #3
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
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.
 
2 members found this post helpful.
Old 09-05-2012, 05:34 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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.
 
Old 09-11-2012, 02:18 AM   #5
bloodstreetboy
Member
 
Registered: May 2012
Posts: 198
Blog Entries: 3

Original Poster
Rep: Reputation: 37
@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.
 
Old 09-12-2012, 04:55 AM   #6
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Remote SSH Login Require User Password Change jbarcia Linux - Security 1 02-28-2012 03:00 AM
Ubuntu 11.04 encrypted LVM password not working after user login password change prateekm21 Linux - Security 0 10-29-2011 02:20 PM
User Password change and Reverse SSH metallica1973 Linux - Server 2 02-18-2009 03:02 PM
Cannot change root password (let alone standard user's password) jbottiger Red Hat 4 01-06-2009 09:03 PM
Locking out a user when password expires, but allowing them to change their password kaplan71 Linux - Security 5 06-27-2008 08:12 PM


All times are GMT -5. The time now is 06:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration