ssh/ssh-copy-id

ssh/ssh-copy-id

OpenWrt、Windows 10 等系统没有 ssh-copy-id, 可以自己写个脚本实现基本的 ssh-copy-id 功能:

ssh-copy-id.sh

/usr/bin/ssh-copy-id.sh

#!/bin/sh

if [ "$#" -ne 1 ]; then
  echo "Example: ${0} root@192.168.1.1"
  exit 1
fi

cat ~/.ssh/id_rsa.pub | ssh ${1} "cat >> ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys && chmod 0700 ~/.ssh"

ssh-copy-id.bat

Windows 版的 OpenSSH 也没有 ssh-copy-id,可以用下面这个 bat 脚本实现基本功能(交互式):

@echo Off
title ssh-copy-id For Windows

set /p USR=User: 
set /p SRV=Server: 

where ssh >nul 2>nul

if %ErrorLevel% == 0 (
  echo SSH Found, sending key to server
  type %SystemDrive%%HomePath%\.ssh\id_rsa.pub | ssh %USR%@%SRV% "cat >> .ssh/authorized_keys"
) else (
  echo SSH NOT Found, please install or put in the System PATH
)

Last update: 2021-01-14 01:28:51 UTC