基于GitHub的快速ssh pubkey导入

Yamako 发布于 2024-12-10 142 次阅读


由于使用越来越多的个人设备以及服务器,为了保障安全性以及便利性,使用ssh key进行ssh连接是及其有效的方法。然而,频繁的在各设备部署ssh公钥随着设备数的增多愈发繁杂,且难以快速同步。

常见的 ssh 公钥部署方法如下:

mkdir .ssh
chmod 700 ~/.ssh
touch .ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
echo 'xxxxx' >> .ssh/authorized_keys

另一方面,由于Github进一步收紧基于https的push和clone方式,基于ssh的方式在日常GitHub使用中愈发常用。而借助Github亦可以同时有效的对个人的ssh pubkey进行管理和同步。

在Github中添加SSH keys

进入GitHub设置中,进入SSH and GPG keys选单。

点击 New SSH key

Title 填入备注,注意这个备注不可以更改,如需更改需要Delete后重新Add。在Key 填入设备的ssh pubkey,点击Add SSH key就完成了添加。

在被访问设备上快速导入Github中的SSH keys

参考文章:https://p3terx.com/archives/ssh-key-installer.html

项目Github:https://github.com/P3TERX/SSH_Key_Installer

通过P3TERX大佬的一键导入脚本即可快速将在Github上的ssh pubkey部署在被访问设备上。同时还能实现其他的更多丰富功能,例如从链接或是本地文件导入等。

bash <(curl -fsSL git.io/key.sh) [options...] <arg>

参数

  • -o - Overwrite mode, this option is valid at the top
  • -g - Get the public key from GitHub, the arguments is the GitHub ID
  • -u - Get the public key from the URL, the arguments is the URL
  • -f - Get the public key from the local file, the arguments is the local file path
  • -p - Change SSH port, the arguments is port number
  • -d - Disable password login

下方是一个基于Github导入的例子:

bash <(curl -fsSL git.io/key.sh) -g <Username>

本文作者:Yamako

本文链接:https://tamayama.xyz/2024/12/10/基于github的快速ssh-pubkey导入/

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。非商业转载及引用请注明出处(作者、原文链接),商业转载请联系作者获得授权。

Tech otaku, intrested in ACG, AI, and saving the world.
最后更新于 2025-04-10