如何自动将ssh公钥添加到authorized_keys文件?

时间:2021-07-22 14:28:11

I am looking for the simplest set of commands you can run for adding your public key to the authorized_keys files of the root account on a remote server.

我正在寻找可以运行的最简单的命令集,用于将公钥添加到远程服务器上root帐户的authorized_keys文件中。

We assume that the current user has login access to the remote server and it is also listed in the sudoers file.

我们假设当前用户具有对远程服务器的登录访问权限,并且它也列在sudoers文件中。

Running the command twice should have no effect.

两次运行命令应该没有任何效果。

1 个解决方案

#1


8  

How about running the ssh-copy-id command? Man pages says the following:

运行ssh-copy-id命令怎么样?手册页说明如下:

ssh-copy-id - install your public key in a remote machine's authorized_keys

ssh-copy-id - 在远程计算机的authorized_keys中安装您的公钥

Sounds exactly what you're looking for? I have never tried running the command twice, though. It may not check for that.

听起来你正在寻找什么?不过,我从未尝试过两次运行命令。它可能无法检查。

#1


8  

How about running the ssh-copy-id command? Man pages says the following:

运行ssh-copy-id命令怎么样?手册页说明如下:

ssh-copy-id - install your public key in a remote machine's authorized_keys

ssh-copy-id - 在远程计算机的authorized_keys中安装您的公钥

Sounds exactly what you're looking for? I have never tried running the command twice, though. It may not check for that.

听起来你正在寻找什么?不过,我从未尝试过两次运行命令。它可能无法检查。