Lek*_*eyn 521 ssh command-line
生成的 SSH 私钥ssh-keygen包含公钥部分。如何从私钥中检索此公钥?我丢失了我的公钥,需要将此公钥的内容放在服务器authorized_keys文件中,并且不想创建新的密钥对。
或者说:如何id_rsa.pub从id_rsa文件创建文件?
Lek*_*eyn 789
我在 Server Fault: Create a public SSH key from the private key上找到了答案?
该选项-y输出公钥:
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)
作为旁注,公钥的注释丢失了。我有一个需要评论的网站(Launchpad?),所以您需要编辑~/.ssh/id_rsa.pub评论并将评论附加到第一行,评论和关键数据之间有一个空格。下面显示了一个示例公钥。
ssh-rsa AAAA..../VqDjtS5 ubuntu@ubuntu
Run Code Online (Sandbox Code Playgroud)
对于添加到 SSH 代理的密钥(在后台运行并避免需要一遍又一遍地重新输入密钥文件密码的程序),您可以使用该ssh-add -L命令列出添加到的密钥的公钥代理(通过ssh-add -l)。当 SSH 密钥存储在智能卡上(并且无法访问私钥文件)时,这很有用。
小智 15
This is a solution is specifically for users using Windows to SSH into their remote machines, including cloud images on Amazon AWS and GCE.
I recently used this solution to remote log in to new deployed VM images on GCE.
Generate a key/pair or use an existing private key:
If you have a private key:
Open puttygen, press load button and select your private key (*.pem) file.
If you do not have a private key:

Create a new 'authorized_keys' file (with Notepad):
Copy your public key data from the "Public key for pasting into OpenSSH authorized_keys file" section of the PuTTY Key Generator, and paste the key data to the "authorized_keys" file.
Make sure there is only one line of text in this file.
Upload the key to a Linux server:
Upload authorized_keys file to the home directory at the remote machine.
Set proper permissions:
Make a .ssh directory (if it does not exist)
Copy the authorized_keys file to the .ssh directory (this will replace any existing authorized_keys file; take note of this).
If the file exists, simply add the contents of this file to the existing file.
Run commands to set permissions:
sudo chmod 700 .ssh && chmod 600 .ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
Now you will be able to ssh into a remote machine without entering credentials every time.