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
Dynamically adding ssh keys. #341
Comments
Right now, there's no way to modify the set of options associated with an SSH listener once it has been created, and among other things those options include the set of server host keys to use. However, as a workaround, you should be able to close the existing listener and start a new one very quickly, and it wouldn't affect existing connections. There might be a small window where you're not accepting connections, but I wouldn't expect it to be very noticeable, particularly if you used the SSHServerConnectionOptions object to get everything ready to go before doing the switchover. You could even pass the previous "options" object to the new one, just updating the parts you want to change, so you don't have to repeat all those other arguments multiple times. Allowing the listener's options to be updated dynamically should be possible, but it would require some rearranging of the way the options object works. Right now, that object is designed to basically be immutable once created. You can derive new sets of options from an existing set, but that makes a copy and doesn't change the original object. |
Ohh okay thank you! |
I took a look at this today, and it turned out to be fairly straightforward to do -- see commit 5990144 in the "develop" branch. It adds an update() method on the object returned by listen/listen_reverse which takes the same keyword arguments as listen/listen_reverse does, allowing you to change any of these setting and have that change apply to future accepted connections. The only thing you can't change is settings related to setting up the listening sockets themselves. For that, you need to do a new listen call. In your example, you'd do something like: listener = await asyncssh.create_server(
MainSSHServer, '', settings['settings']['port'],
server_host_keys=['ext/keys/main/id_rsa'],
authorized_client_keys=get_ssh_keys(),
process_factory=handle_client
) and then sometime later: listener.update(server_host_keys=['some_new_list_of_keys']) You could add any other parameters present in SSHServerConnectionOptions as well with the same approach, setting whichever options you want to change. |
oh thank you so much! that makes my work a lot easier thanks :) |
Sorry for the late response :/ |
No problem - let me know if you have any problems with it. |
This is now available in AsyncSSH 2.6.0. |
How do I dynamically add SSH keys to my asyncSSH server?
I know I can hard code them in here, but how do I add them after the server is up?
The text was updated successfully, but these errors were encountered: