id_rsa
的权限必须是 400
或 600
.
.ssh
的权限必须是 700
.
在网上发现了如下的代码可以快速的将公用密匙上传到远程服务器上。
cat <路径>/id_rsa.pub | ssh <用户名>@<服务器地址> 'cat >> .ssh/authorized_keys && echo "Key copied"'
比如:
cat ~/.ssh/id_rsa.pub | ssh xxx@xxx.com 'cat >> .ssh/authorized_keys && echo "Key copied"'