Implement a command for installing SSH public key into remote machine #17686

Closed
opened 2026-01-31 05:50:12 +00:00 by claunia · 2 comments
Owner

Originally created by @martinreinok on GitHub (Jun 11, 2022).

Description of the new feature/enhancement

The proposed command would install current user's SSH public key into target machine's authorized_keys file, which allows for a secure way to SSH without entering a password. Ideally this would be possible cross-platform (Windows, UNIX, MacOS).

A rather cumbersome alternative exists currently:
Get-Content $env:USERPROFILE\.ssh\id_rsa.pub | ssh <user>@<hostname> "cat >> .ssh/authorized_keys"
This could be simplified to:
ssh-copy-id <user>@<hostname>
If "ssh-copy-id" can not be used as the command name, it can be renamed to something similar (e.g. ssh-copy-key).

For UNIX reference, the ssh-copy-id documentation
ssh-copy-id man page

Proposed technical implementation details (optional)

  • The proposed command would ssh into the remote machine, presumably using a password.

  • If successful, it would check for the authorized_keys file (differs depending on OS), creating it if necessary or exiting the command if the host's key already exists in the file.

  • Then it would copy the host's default public key contents into the authorized_keys file.

  • Finally it might have to change the permissions of the remote user's home, ~/.ssh, and ~/.ssh/authorized_keys to remove group writability, which would otherwise prevent user from logging in, if the remote sshd configuration has StrictModes set in its configuration.

  • Optional arguments should be available [-f] force [-n] print local key [-i] identity file path [-p] port [-o ssh_option]

Originally created by @martinreinok on GitHub (Jun 11, 2022). # Description of the new feature/enhancement The proposed command would install current user's SSH public key into target machine's authorized_keys file, which allows for a secure way to SSH without entering a password. Ideally this would be possible cross-platform (Windows, UNIX, MacOS). A rather cumbersome alternative exists currently: `Get-Content $env:USERPROFILE\.ssh\id_rsa.pub | ssh <user>@<hostname> "cat >> .ssh/authorized_keys"` This could be simplified to: `ssh-copy-id <user>@<hostname>` If "ssh-copy-id" can not be used as the command name, it can be renamed to something similar (e.g. ssh-copy-key). For UNIX reference, the `ssh-copy-id` documentation [ssh-copy-id man page](https://manpages.org/ssh-copy-id) # Proposed technical implementation details (optional) - The proposed command would ssh into the remote machine, presumably using a password. - If successful, it would check for the authorized_keys file (differs depending on OS), creating it if necessary or exiting the command if the host's key already exists in the file. - Then it would copy the host's default public key contents into the authorized_keys file. - Finally it might have to change the permissions of the remote user's home, ~/.ssh, and ~/.ssh/authorized_keys to remove group writability, which would otherwise prevent user from logging in, if the remote sshd configuration has StrictModes set in its configuration. - Optional arguments should be available [-f] force [-n] print local key [-i] identity file path [-p] port [-o ssh_option]
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-Fix labels 2026-01-31 05:50:12 +00:00
Author
Owner

@j0le commented on GitHub (Jun 11, 2022):

Hi @martinreinok,

I think, this is not the right repository for your request. Windows Terminal is just a terminal emulator and not a program, that interprets commands (which is called a shell, like powershell). (https://www.hanselman.com/blog/whats-the-difference-between-a-console-a-terminal-and-a-shell)

The right place for your request might be here:
https://github.com/PowerShell/openssh-portable

as documented here:
https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview

The git-for-windows distribution comes with ssh-copy-id. Maybe that helps.
It's a unix shell script, that can be interpreted by bash, which also comes with git-for-windows. Therefore it works on Windows.

@j0le commented on GitHub (Jun 11, 2022): Hi @martinreinok, I think, this is not the right repository for your request. Windows Terminal is just a terminal emulator and not a program, that interprets commands (which is called a shell, like powershell). (https://www.hanselman.com/blog/whats-the-difference-between-a-console-a-terminal-and-a-shell) The right place for your request might be here: https://github.com/PowerShell/openssh-portable as documented here: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview The git-for-windows distribution comes with ssh-copy-id. Maybe that helps. It's a unix shell script, that can be interpreted by bash, which also comes with git-for-windows. Therefore it works on Windows.
Author
Owner

@martinreinok commented on GitHub (Jun 11, 2022):

Alright, thanks for the links, I put myself up to date with the differences. I'll direct my request to the PowerShell team.

@martinreinok commented on GitHub (Jun 11, 2022): Alright, thanks for the links, I put myself up to date with the differences. I'll direct my request to the PowerShell team.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17686