pub_keys v0.0.1 PubKeys

This mix project uses an Elixir script to manage public keys from a git server. It can add and remove public keys from all targetted servers.

  • pub_keys --help to get help
  • pub_keys --add "key here" to add key to all servers
  • pub_keys --remove "key here" to remove key from all servers
  • pub_keys --deploy-all to push out auth_keys files to all servers (if you want to add a key to files manually, for example)

Summary

Functions

Prepend a key into the authorized_keys file if the key doesn’t exist inside the file yet

Given a list of ssh_keys files and the directory path of the files, this method will run scp_to_server to copy the ssh key file to each remote server as per the ip address in the file name, and overwrite the remote authorized keys file

Prepends a key inside the specified authorized_keys file

Given an input of remote server’s IP address, and the directory path to ssh key files, returns a tuple containing the ip address and a list of the ssh_keys

Examples

iex> path = PubKeys.Helper.files_path(:test)
iex> PubKeys.read_keys("192.168.0.10", path)
{"192.168.0.10", ["ssh-rsa ABCD123abcd test1@work", "ssh-rsa XYZ987abcd test2@work"]}

Remove a key inside the specified authorized_keys file

Remove a key in the authorized_keys file if it does not exist inside the file

Given a file with IP Address as the name and the remote path where the authorized ssh keys are stored in the remote server. This method will run scp system command from the specified file to the path in the remote server where the IP Address file name indicates

Functions

add_user_key(ssh_key, files_list, path)

Prepend a key into the authorized_keys file if the key doesn’t exist inside the file yet

deploy_all(files_list, path)

Given a list of ssh_keys files and the directory path of the files, this method will run scp_to_server to copy the ssh key file to each remote server as per the ip address in the file name, and overwrite the remote authorized keys file.

main(options)
output()
prepend_key(arg, key, path)

Prepends a key inside the specified authorized_keys file

read_keys(ip, path)

Given an input of remote server’s IP address, and the directory path to ssh key files, returns a tuple containing the ip address and a list of the ssh_keys

Examples

iex> path = PubKeys.Helper.files_path(:test)
iex> PubKeys.read_keys("192.168.0.10", path)
{"192.168.0.10", ["ssh-rsa ABCD123abcd test1@work", "ssh-rsa XYZ987abcd test2@work"]}
remove_key(arg, key, path)

Remove a key inside the specified authorized_keys file

remove_user_key(ssh_key, files_list, path)

Remove a key in the authorized_keys file if it does not exist inside the file

scp_to_server(file, path)

Given a file with IP Address as the name and the remote path where the authorized ssh keys are stored in the remote server. This method will run scp system command from the specified file to the path in the remote server where the IP Address file name indicates.