Skip to content

Instantly share code, notes, and snippets.

Created July 3, 2017 20:15
Show Gist options
  • Save anonymous/830584f1cc48af018c281696a674f9e1 to your computer and use it in GitHub Desktop.
Save anonymous/830584f1cc48af018c281696a674f9e1 to your computer and use it in GitHub Desktop.
require 'net/ssh'
# get arguments from command line
# decide what to do with them
# and verify they are legit commands
hostname = ARGV[0]
lock = ARGV[1]
user = ARGV[2]
case lock
when "lock"
cmd = "sudo chsh -s /usr/bin/false #{user}"
locker(hostname, cmd)
when "unlock"
cmd = "sudo chsh -s /bin/bash #{user}"
locker(hostname, cmd)
else quit
end
def locker(host, cmd)
begin
ssh = Net::SSH.start(host)
res = ssh.exec!(cmd)
ssh.close
puts res
rescue
puts "Unable to connect to #{@hostname}!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment