SSH + Change password using root
up vote
1
down vote
favorite
I'm trying to connect to various servers to change the password of a specific user.
I hope that you can help me to build a Script to do that thing, the complexity is that I have to use sudo and send the password in order to connect on the remote server as root.
I'm trying something like this but is not working:
sshpass -p pass ssh user@server << EOF
echo pass | sudo -S -u root "echo 'user2:pass2' | chpasswd"
EOF
To better explain what I want to do, these are the steps that I need to do:
- connect to a server with my user.
- using "sudo" to connect as a root.
- execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2.
This is the error:
Pseudo-terminal will not be allocated because stdin is not a terminal. stat: cannot stat `pipe:[2670580091]': No such file or directory [sudo] password for user1: sudo: echo 'user2:XXXXXXX' | chpasswd: command not found
ssh sudo root
add a comment |
up vote
1
down vote
favorite
I'm trying to connect to various servers to change the password of a specific user.
I hope that you can help me to build a Script to do that thing, the complexity is that I have to use sudo and send the password in order to connect on the remote server as root.
I'm trying something like this but is not working:
sshpass -p pass ssh user@server << EOF
echo pass | sudo -S -u root "echo 'user2:pass2' | chpasswd"
EOF
To better explain what I want to do, these are the steps that I need to do:
- connect to a server with my user.
- using "sudo" to connect as a root.
- execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2.
This is the error:
Pseudo-terminal will not be allocated because stdin is not a terminal. stat: cannot stat `pipe:[2670580091]': No such file or directory [sudo] password for user1: sudo: echo 'user2:XXXXXXX' | chpasswd: command not found
ssh sudo root
1
Try adding-tto the ssh command to force it to allocate a tty which sudo requires to enter a password. It would also be helpful to update your answer with how/why that particular command fails (error, hangs, no output etc).
– Michael Daffin
Jan 8 at 22:16
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to connect to various servers to change the password of a specific user.
I hope that you can help me to build a Script to do that thing, the complexity is that I have to use sudo and send the password in order to connect on the remote server as root.
I'm trying something like this but is not working:
sshpass -p pass ssh user@server << EOF
echo pass | sudo -S -u root "echo 'user2:pass2' | chpasswd"
EOF
To better explain what I want to do, these are the steps that I need to do:
- connect to a server with my user.
- using "sudo" to connect as a root.
- execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2.
This is the error:
Pseudo-terminal will not be allocated because stdin is not a terminal. stat: cannot stat `pipe:[2670580091]': No such file or directory [sudo] password for user1: sudo: echo 'user2:XXXXXXX' | chpasswd: command not found
ssh sudo root
I'm trying to connect to various servers to change the password of a specific user.
I hope that you can help me to build a Script to do that thing, the complexity is that I have to use sudo and send the password in order to connect on the remote server as root.
I'm trying something like this but is not working:
sshpass -p pass ssh user@server << EOF
echo pass | sudo -S -u root "echo 'user2:pass2' | chpasswd"
EOF
To better explain what I want to do, these are the steps that I need to do:
- connect to a server with my user.
- using "sudo" to connect as a root.
- execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2.
This is the error:
Pseudo-terminal will not be allocated because stdin is not a terminal. stat: cannot stat `pipe:[2670580091]': No such file or directory [sudo] password for user1: sudo: echo 'user2:XXXXXXX' | chpasswd: command not found
ssh sudo root
ssh sudo root
edited Feb 7 at 10:15
Pierre.Vriens
96841015
96841015
asked Jan 8 at 22:03
Jose
61
61
1
Try adding-tto the ssh command to force it to allocate a tty which sudo requires to enter a password. It would also be helpful to update your answer with how/why that particular command fails (error, hangs, no output etc).
– Michael Daffin
Jan 8 at 22:16
add a comment |
1
Try adding-tto the ssh command to force it to allocate a tty which sudo requires to enter a password. It would also be helpful to update your answer with how/why that particular command fails (error, hangs, no output etc).
– Michael Daffin
Jan 8 at 22:16
1
1
Try adding
-t to the ssh command to force it to allocate a tty which sudo requires to enter a password. It would also be helpful to update your answer with how/why that particular command fails (error, hangs, no output etc).– Michael Daffin
Jan 8 at 22:16
Try adding
-t to the ssh command to force it to allocate a tty which sudo requires to enter a password. It would also be helpful to update your answer with how/why that particular command fails (error, hangs, no output etc).– Michael Daffin
Jan 8 at 22:16
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
I've executed things as root over ssh using:
ssh -t you@server <<EOF
echo pass_for_you | sudo -S bash -c "commands to do as root";
EOF
add a comment |
up vote
0
down vote
would this help ? or something similar ? assuming I understood what you are trying to do ?
for i in server{1,2,3}; do
ssh -t user@$i 'sudo passwd user2'
done
I can't do that because the server have policies where the only user can execute passwd is root. In order to change the password I have to do the next steps: 1) connect to a server with my user 2) using "sudo" to connect as a root 3) execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2
– Jose
Jan 9 at 13:22
for i in server{1,2,3}: do ssh -t user@$i 'sudo su - ; passwd user2 ' done cant remember if that prompts for password or not
– ssvegeta96
Jan 9 at 16:18
add a comment |
up vote
0
down vote
The ansible module "user" should work for your problem. But you have to provide the already crypted password-hash instead.
Make the hash with:
mkpasswd --method=sha-512
Execute a ansible adhoc-command like this with the quoted generated hash-string:
ansible -v all -i <hostname>, --become --extra-vars 'ansible_become_pass=<sudo password> ansible_password=<sudo password>' --user=<ssh user> -k -m user --args='name=root update_password=always password="$6$IZjuXoio1$zHpQQDZGDPwG8mr2R6Mrt1C8Nqstui75enT/o0oSVJ3M6rqff8993kmAaTgbc9q9HTgPD2jtZukEqgeIGKfUN0"'
Prerequesites: ansible and sshpass on client machine.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I've executed things as root over ssh using:
ssh -t you@server <<EOF
echo pass_for_you | sudo -S bash -c "commands to do as root";
EOF
add a comment |
up vote
0
down vote
I've executed things as root over ssh using:
ssh -t you@server <<EOF
echo pass_for_you | sudo -S bash -c "commands to do as root";
EOF
add a comment |
up vote
0
down vote
up vote
0
down vote
I've executed things as root over ssh using:
ssh -t you@server <<EOF
echo pass_for_you | sudo -S bash -c "commands to do as root";
EOF
I've executed things as root over ssh using:
ssh -t you@server <<EOF
echo pass_for_you | sudo -S bash -c "commands to do as root";
EOF
answered Jan 9 at 14:37
gat1
617
617
add a comment |
add a comment |
up vote
0
down vote
would this help ? or something similar ? assuming I understood what you are trying to do ?
for i in server{1,2,3}; do
ssh -t user@$i 'sudo passwd user2'
done
I can't do that because the server have policies where the only user can execute passwd is root. In order to change the password I have to do the next steps: 1) connect to a server with my user 2) using "sudo" to connect as a root 3) execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2
– Jose
Jan 9 at 13:22
for i in server{1,2,3}: do ssh -t user@$i 'sudo su - ; passwd user2 ' done cant remember if that prompts for password or not
– ssvegeta96
Jan 9 at 16:18
add a comment |
up vote
0
down vote
would this help ? or something similar ? assuming I understood what you are trying to do ?
for i in server{1,2,3}; do
ssh -t user@$i 'sudo passwd user2'
done
I can't do that because the server have policies where the only user can execute passwd is root. In order to change the password I have to do the next steps: 1) connect to a server with my user 2) using "sudo" to connect as a root 3) execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2
– Jose
Jan 9 at 13:22
for i in server{1,2,3}: do ssh -t user@$i 'sudo su - ; passwd user2 ' done cant remember if that prompts for password or not
– ssvegeta96
Jan 9 at 16:18
add a comment |
up vote
0
down vote
up vote
0
down vote
would this help ? or something similar ? assuming I understood what you are trying to do ?
for i in server{1,2,3}; do
ssh -t user@$i 'sudo passwd user2'
done
would this help ? or something similar ? assuming I understood what you are trying to do ?
for i in server{1,2,3}; do
ssh -t user@$i 'sudo passwd user2'
done
edited Jan 9 at 16:19
answered Jan 8 at 23:09
ssvegeta96
577
577
I can't do that because the server have policies where the only user can execute passwd is root. In order to change the password I have to do the next steps: 1) connect to a server with my user 2) using "sudo" to connect as a root 3) execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2
– Jose
Jan 9 at 13:22
for i in server{1,2,3}: do ssh -t user@$i 'sudo su - ; passwd user2 ' done cant remember if that prompts for password or not
– ssvegeta96
Jan 9 at 16:18
add a comment |
I can't do that because the server have policies where the only user can execute passwd is root. In order to change the password I have to do the next steps: 1) connect to a server with my user 2) using "sudo" to connect as a root 3) execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2
– Jose
Jan 9 at 13:22
for i in server{1,2,3}: do ssh -t user@$i 'sudo su - ; passwd user2 ' done cant remember if that prompts for password or not
– ssvegeta96
Jan 9 at 16:18
I can't do that because the server have policies where the only user can execute passwd is root. In order to change the password I have to do the next steps: 1) connect to a server with my user 2) using "sudo" to connect as a root 3) execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2
– Jose
Jan 9 at 13:22
I can't do that because the server have policies where the only user can execute passwd is root. In order to change the password I have to do the next steps: 1) connect to a server with my user 2) using "sudo" to connect as a root 3) execute "echo 'user2:pass2' | chpasswd" in order to change the password of the user2
– Jose
Jan 9 at 13:22
for i in server{1,2,3}: do ssh -t user@$i 'sudo su - ; passwd user2 ' done cant remember if that prompts for password or not
– ssvegeta96
Jan 9 at 16:18
for i in server{1,2,3}: do ssh -t user@$i 'sudo su - ; passwd user2 ' done cant remember if that prompts for password or not
– ssvegeta96
Jan 9 at 16:18
add a comment |
up vote
0
down vote
The ansible module "user" should work for your problem. But you have to provide the already crypted password-hash instead.
Make the hash with:
mkpasswd --method=sha-512
Execute a ansible adhoc-command like this with the quoted generated hash-string:
ansible -v all -i <hostname>, --become --extra-vars 'ansible_become_pass=<sudo password> ansible_password=<sudo password>' --user=<ssh user> -k -m user --args='name=root update_password=always password="$6$IZjuXoio1$zHpQQDZGDPwG8mr2R6Mrt1C8Nqstui75enT/o0oSVJ3M6rqff8993kmAaTgbc9q9HTgPD2jtZukEqgeIGKfUN0"'
Prerequesites: ansible and sshpass on client machine.
add a comment |
up vote
0
down vote
The ansible module "user" should work for your problem. But you have to provide the already crypted password-hash instead.
Make the hash with:
mkpasswd --method=sha-512
Execute a ansible adhoc-command like this with the quoted generated hash-string:
ansible -v all -i <hostname>, --become --extra-vars 'ansible_become_pass=<sudo password> ansible_password=<sudo password>' --user=<ssh user> -k -m user --args='name=root update_password=always password="$6$IZjuXoio1$zHpQQDZGDPwG8mr2R6Mrt1C8Nqstui75enT/o0oSVJ3M6rqff8993kmAaTgbc9q9HTgPD2jtZukEqgeIGKfUN0"'
Prerequesites: ansible and sshpass on client machine.
add a comment |
up vote
0
down vote
up vote
0
down vote
The ansible module "user" should work for your problem. But you have to provide the already crypted password-hash instead.
Make the hash with:
mkpasswd --method=sha-512
Execute a ansible adhoc-command like this with the quoted generated hash-string:
ansible -v all -i <hostname>, --become --extra-vars 'ansible_become_pass=<sudo password> ansible_password=<sudo password>' --user=<ssh user> -k -m user --args='name=root update_password=always password="$6$IZjuXoio1$zHpQQDZGDPwG8mr2R6Mrt1C8Nqstui75enT/o0oSVJ3M6rqff8993kmAaTgbc9q9HTgPD2jtZukEqgeIGKfUN0"'
Prerequesites: ansible and sshpass on client machine.
The ansible module "user" should work for your problem. But you have to provide the already crypted password-hash instead.
Make the hash with:
mkpasswd --method=sha-512
Execute a ansible adhoc-command like this with the quoted generated hash-string:
ansible -v all -i <hostname>, --become --extra-vars 'ansible_become_pass=<sudo password> ansible_password=<sudo password>' --user=<ssh user> -k -m user --args='name=root update_password=always password="$6$IZjuXoio1$zHpQQDZGDPwG8mr2R6Mrt1C8Nqstui75enT/o0oSVJ3M6rqff8993kmAaTgbc9q9HTgPD2jtZukEqgeIGKfUN0"'
Prerequesites: ansible and sshpass on client machine.
answered Nov 21 at 15:30
linuxlupus
113
113
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f415684%2fssh-change-password-using-root%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Try adding
-tto the ssh command to force it to allocate a tty which sudo requires to enter a password. It would also be helpful to update your answer with how/why that particular command fails (error, hangs, no output etc).– Michael Daffin
Jan 8 at 22:16