みーのぺーじ

みーが趣味でやっているPCやソフトウェアについて.Python, Javascript, Processing, Unityなど.

authorized_keys を追加

scp コマンドでリモートにファイルをコピーするときに,SSHをパスワード認証で使用しているとうまくいかないので,鍵を作成してSSH公開鍵認証を使用します.

なお,リモートは user@remote.local と表記しますので,適宜読み替えてください.

MacOS, Linux

ssh-copy-id コマンドを使います*1

$ ssh-keygen -t ecdsa
$ ssh-copy-id -i ~/.ssh/id_ecdsa.pub user@remote.local

専用のスクリプトが用意されているので,便利ですね.

Windows

ssh-copy-id コマンドはないので,PowerShell にて以下のコマンドを実行します.

まず,リモートに .ssh ディレクトリを作成します.作成済みならば不要です.

> ssh user@remote.local
$ mkdir -p .ssh
$ exit

鍵を生成して,リモートの .ssh/authorized_keys に保存します.

>  ssh-keygen -t ecdsa
>  cat .\.ssh\id_ecdsa.pub | ssh user@remote.local 'cat >> .ssh/authorized_keys'

MacOS や Linux と比較すると少し面倒ですが,同様のことが実現できます.

*1:ssh-copy-id is a script that uses ssh(1) to log into a remote machine. https://manpages.ubuntu.com/manpages/trusty/man1/ssh-copy-id.1.html