Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python - Find public keys matching a given list of patterns
def contents(ssh, files):
for file in files:
path = '{}/{}'.format(ssh, file)
yield open(path).read().replace("\n", "")
def keysFor(args):
ssh = '{}/.ssh'.format(os.environ['HOME'])
extensions = [ '.pub' ]
files = [f for f in os.listdir(ssh) if os.path.splitext(f)[1] in extensions]
keys = [k for k in contents(ssh, files) if k.split(' ')[2] in args]
for key in keys:
yield key
def main(args):
keys = keysFor(args)
for key in keys:
print(key)
if __name__ == '__main__':
main(sys.argv[1:])
@frgomes

This comment has been minimized.

Copy link
Owner Author

@frgomes frgomes commented Feb 9, 2021

Call like this:

#!/bin/bash

./find_public_keys.py rgomes@example.com rgomes@localhost rgomes@laptop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment