Skip to content

Instantly share code, notes, and snippets.

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:
if __name__ == '__main__':

This comment has been minimized.

Copy link
Owner Author

@frgomes frgomes commented Feb 9, 2021

Call like this:


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