-
-
Save KINGSABRI/a0adb7d7cc9eae438e0f to your computer and use it in GitHub Desktop.
Change Expired Linux Password
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' | |
host = IO.readlines('/path/to/your/servers.list') # full path of servers' list | |
i = 0 | |
while i != host.length | |
Net::SSH.start(host[i], 'emerg', :password => "oldpass" , :verbose=> :warn) do |ssh| | |
puts "-------------------------------------" | |
puts "|#--> IP-address: #{host[i]}" | |
puts "-------------------------------------" | |
ssh.open_channel do |channel| | |
channel.on_request "exit-status" do |channel, data| | |
$exit_status = data.read_long | |
end | |
channel.on_data do |channel, data| | |
puts data.inspect | |
if data.inspect.include? "current" | |
channel.send_data("oldpass\n"); | |
elsif data.inspect.include? "New" | |
channel.send_data("newpass\n"); | |
elsif data.inspect.include? "new" | |
channel.send_data("newpass\n"); | |
sleep 0.1 | |
end | |
end | |
channel.request_pty | |
# This will just safely fail if we have already a password prompt on | |
channel.exec("passwd"); | |
channel.wait | |
# Will reflect a valid status in both cases | |
puts $exit_status | |
end | |
ssh.loop | |
end | |
i += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment