-
-
Save KINGSABRI/cfb801c102f31c327eb5 to your computer and use it in GitHub Desktop.
Change Password remotly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ssh' | |
Net::SSH.start('127.0.0.1', 'user', :password => "pass") do |ssh| | |
ssh.open_channel do |channel| | |
channel.on_request "exit-status" do |channel, data| | |
$exit_status = data.read_long | |
end | |
channel.request_pty do |channel, success| | |
channel.exec("sudo passwd UserName") # Logged user shuold be root or sudoers memeber | |
if success | |
channel.on_data do |channel, data| | |
puts data.inspect.chomp("\r\n") | |
channel.send_data("NewpassOfUserName\n") | |
sleep 0.1 | |
end | |
else | |
puts "FAILED!!" | |
end | |
end | |
channel.wait | |
puts "SUCCESS!!" if $exit_status == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment