Skip to content

ssh-copy-id fails if powershell is default shell #4691

@SteveL-MSFT

Description

@SteveL-MSFT

ssh-copy-id is a popular shebang bash script to make it easy to deploy public keys on target machines for key based authn.
The problem is that this script uses the POSIX shell cmd exec which is unknown to powershell:

ssh "$@" "exec sh -c 'cd ; umask 077 ; mkdir -p .ssh && cat >> .ssh/authorized_keys

This can block adoption of powershell as the default shell (via chsh)

Steps to reproduce

PS> ssh-copy-id user@host

Expected behavior

Success

Actual behavior

ssh-copy-id user@host/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
user@host's password: 
exec : The term 'exec' is not recognized as the name of a cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a path 
was included, verify that the path is correct and try again.
At line:1 char:1
+ exec sh -c 'cd ; umask 077 ; mkdir -p .ssh && cat >> .ssh/authorized_ ...
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (exec:String) [], CommandNotFoun 
   dException
    + FullyQualifiedErrorId : CommandNotFoundException

Environment data

Name                           Value                                                                                                
----                           -----                                                                                                
PSVersion                      6.0.0-beta                                                                                           
PSEdition                      Core                                                                                                 
GitCommitId                    v6.0.0-beta.6                                                                                        
OS                             Linux 4.10.0-32-generic #36~16.04.1-Ubuntu SMP Wed Aug 9 09:19:02 UTC 2017                           
Platform                       Unix                                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                              
PSRemotingProtocolVersion      2.3                                                                                                  
SerializationVersion           1.1.0.1                                                                                              
WSManStackVersion              3.0             

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionResolution-FixedThe issue is fixed.WG-DevEx-Portabilityauthoring cross-platform or cross-architecture modules, cmdlets, and scripts

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions