add-ssh-copy-id.ps1
· 506 B · PowerShell
Неформатований
$FunctionCode = @'
function ssh-copy-id {
param([Parameter(Mandatory=$true)][string]$RemoteTarget)
$KeyPath = "$env:USERPROFILE\.ssh\id_ed25519.pub"
if (!(Test-Path $KeyPath)) {
Write-Error "Public key not found at $KeyPath"
return
}
$PubKey = Get-Content $KeyPath
ssh $RemoteTarget "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '$PubKey' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
}
'@
Add-Content -Path $PROFILE -Value $FunctionCode
. $PROFILE
| 1 | $FunctionCode = @' |
| 2 | function ssh-copy-id { |
| 3 | param([Parameter(Mandatory=$true)][string]$RemoteTarget) |
| 4 | $KeyPath = "$env:USERPROFILE\.ssh\id_ed25519.pub" |
| 5 | if (!(Test-Path $KeyPath)) { |
| 6 | Write-Error "Public key not found at $KeyPath" |
| 7 | return |
| 8 | } |
| 9 | $PubKey = Get-Content $KeyPath |
| 10 | ssh $RemoteTarget "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '$PubKey' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys" |
| 11 | } |
| 12 | '@ |
| 13 | |
| 14 | Add-Content -Path $PROFILE -Value $FunctionCode |
| 15 | |
| 16 | . $PROFILE |