From 762e4001567b19a94d235f3c76d8bdcba04d1642 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Mon, 22 Jun 2026 01:34:40 +0200 Subject: [PATCH 1/2] Add editable SSH public keys for existing Unix users This PR adds SSH public key management to the Users and Groups edit flow for existing Unix users. Webmin stores its managed key with a readable marker in `authorized_keys`, validates submitted public keys, preserves unrelated keys, supports rename/update/remove flows, and performs user `.ssh` file operations as the target Unix user. https://github.com/webmin/webmin/issues/1827 --- useradmin/edit_user.cgi | 10 +- useradmin/help/sshkey.html | 7 +- useradmin/lang/en | 8 ++ useradmin/save_user.cgi | 42 ++++--- useradmin/user-lib.pl | 220 +++++++++++++++++++++++++++++++++++++ 5 files changed, 261 insertions(+), 26 deletions(-) diff --git a/useradmin/edit_user.cgi b/useradmin/edit_user.cgi index 4fa0b24cb..e00455fcc 100755 --- a/useradmin/edit_user.cgi +++ b/useradmin/edit_user.cgi @@ -221,11 +221,11 @@ print &ui_table_row(&hlink($text{'pass'}, "pass"), $text{'uedit_disabled'}, $disabled) : "") ); -# Show SSH public key field, for new users -if ($n eq '') { - print &ui_table_row(&hlink($text{'sshkey'}, "sshkey"), - &ui_textarea("sshkey", undef, 3, 60), 3); - } +# Show SSH public key field. Existing users only display the Webmin-managed +# key, identified by our marker in authorized_keys; unrelated keys stay hidden. +my $sshkey = $n ne '' ? &get_user_ssh_pubkey(\%uinfo) : undef; +print &ui_table_row(&hlink($text{'sshkey'}, "sshkey"), + &ui_textarea("sshkey", $sshkey, 4, 60), 3); print &ui_table_end(); diff --git a/useradmin/help/sshkey.html b/useradmin/help/sshkey.html index 5e026555e..f2004a947 100644 --- a/useradmin/help/sshkey.html +++ b/useradmin/help/sshkey.html @@ -1,7 +1,8 @@
SSH public key
-If supplied, the SSH key will be added to the new user's -authorized_keys file to allow an SSH login without a password using -the matching private key.

+If supplied, the SSH key will be added to the user's authorized_keys +file to allow an SSH login without a password using the matching private key. +For existing users, only the key managed by Webmin is shown and updated. Other +keys in authorized_keys are left unchanged.