当我从命令行生成 SSH 公钥时,为什么我的主机名会附加到它?

Cod*_*rer 4 ssh bash ubuntu ssh-keys

当我在 Ubuntu 上通过 Bash 文件生成 SSH 密钥时,我的 PC 的计算机名称(我猜就是这样)会自动添加到该 SSH 密钥中。

这是在 bash 文件中生成密钥的部分:

# Create new ssh-key
echo | ssh-keygen -P ''

# Cat the ssh-key to print on the screen
cat ~/.ssh/id_rsa.pub

Output: ssh-rsa AAAAB....JpyT+gt pc172@pc172-centre-540S-03ILL
Run Code Online (Sandbox Code Playgroud)

为什么这部pc172@pc172-centre-540S-03ILL分会添加到生成的密钥中?

上面的部分类似于我的终端内路径之前显示的文本。

c172@pc172-centre-540S-03ILL:/var/www/new-project-ubuntu$ 
Run Code Online (Sandbox Code Playgroud)

小智 9

最后一部分是评论。通常评论看起来就username@hostname在那里。此评论部分不是强制性的,而是良好的做法。由此您可以知道您将公钥存放在服务器上,它属于谁。

id_rsa.pub您可以随时在文件中或放置注释的任何位置更改注释。如果您想在密钥生成时指定注释,请使用添加-C标志

ssh-keygen -C "comment"
Run Code Online (Sandbox Code Playgroud)