Created
July 27, 2011 13:24
-
-
Save elight/1109341 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
CHARACTERS = (('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a) | |
GROUP = 53 | |
def ridiculous_password | |
(1..20).map do | |
CHARACTERS[rand(CHARACTERS.length)] | |
end.join | |
end | |
def create_ssh_user(username) | |
`dscl . -create /Users/#{username}` | |
`dscl . -create /Users/#{username} UserShell /bin/bash` | |
`dscl . -create /Users/#{username} RealName "#{username}"` | |
`dscl . -create /Users/#{username} UniqueID #{rand(100_000)}` | |
`dscl . -create /Users/#{username} PrimaryGroupID #{GROUP}` #console users | |
`dscl . -create /Users/#{username} NFSHomeDirectory /Users/#{username}` | |
`mkdir -p /Users/#{username}/.ssh` | |
`dscl . -passwd /Users/#{username} #{ridiculous_password}` | |
end | |
def delete_user(username) | |
`rm -rf /Users/#{username}` | |
`dscl . -delete /Users/#{username}` | |
end | |
username = ARGV.shift | |
pub_key_filepath = ARGV.shift | |
user_path = "/Users/#{username}" | |
create_ssh_user username | |
`cp #{pub_key_filepath} #{user_path}/.ssh` | |
`cat #{pub_key_filepath} > #{user_path}/.ssh/authorized_keys` | |
`chown -R #{username} #{user_path}` | |
`chgrp -R #{GROUP} #{user_path}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment