-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read/write AuthorizedKeysFile #92
Comments
What would be the usecase for this? To me, it sounds like a better idea to write whatever data was used as a source when loading authorized_keys to this library. If this library would allow modifying key options, then writing would definitely make sense. |
The use case would be for writing code that manages the contents of authorized keys files. So, load an authorized_keys file into an instance of the class, replace one or more keys, then write the file out again. The class wouldn't necessarily need to do file management itself, but it could have a |
I threw together an example of what I'm talking about at mpounsett/python-sshpubkeys@34b8d7c Usage would look something like this (using StringIO in place of a real file): import io
from sshpubkeys import AuthorizedKeysFile
from tests.valid_keys import keys
# slice 3 keys off the top of the test keys
authorized_keys = "\n".join([x[0] for x in keys][:3])
f = io.StringIO(authorized_keys)
key_file = AuthorizedKeysFile(f, strict=False)
# modify the key list here
f.seek(0)
f.write(str(key_file))
f.seek(0)
print(f.read()) If you really wanted to get fancy, with open(keyfile, mode='w') as f:
with AuthorizedKeysFile(f, strict=False) as key_list:
key_list.append(SSHKey(...)) |
Any news on that? It could be quite useful for me. |
It would be helpful to also be able to write the contents of an AuthorizedKeysFile instance out to disk, in addition to parsing authorized_keys. This probably wouldn't involve too much refactoring of the class.
The text was updated successfully, but these errors were encountered: