Stop Manually Copying SSH Public Keys: One-Click Import from GitHub on Linux Servers
Just enter a GitHub username and automatically import SSH public keys? Ubuntu's lazy-person feature is pretty handy. Isn't the principle just scraping `https://github.com/用户名.keys`? You can do it manually with `curl`, and installing `ssh-import-id` is more efficient, but who cares about all that fancy stuff.
目录6 个章节
Introduction
A highlight of the Ubuntu installer (Subiquity) is that you can automatically import SSH public keys just by entering a GitHub username.
It greatly simplifies the initial setup of a new server, saving you the hassle of manually copying and pasting that long string of SSH Public Key.
How It Works
GitHub provides a public SSH public key access endpoint for every user.
Anyone's public keys are public information; you just need to visit the following URL pattern in a browser or terminal: https://github.com/你的用户名.keys
When you enter a username, the Ubuntu installer performs something like the following in the background:
- Access
https://github.com/username.keysvia a network request. - Retrieve the plaintext public key list returned by that page.
- Append these public keys to the corresponding user's
~/.ssh/authorized_keysfile on the server. - Ensure the
.sshdirectory andauthorized_keysfile have the correct permissions (usually 700 and 600).
How to Do It?
Method 1: Use ssh-import-id (Most Recommended)
That Ubuntu feature actually invokes the ssh-import-id tool, which is also available in Debian's official repositories.
-
Install the tool:
Bash
sudo apt update && sudo apt install ssh-import-id -y -
Import the public key:
Bash
ssh-import-id gh:你的GitHub用户名Note: The
gh:prefix stands for GitHub; it also supports Launchpad (usinglp:).
Method 2: Pure Manual Universal Command (No Extra Tools Needed)
If you don't want to install extra packages, you can also get it done directly with curl and a pipe:
Bash
mkdir -p ~/.ssh && chmod 700 ~/.ssh
curl -L https://github.com/你的用户名.keys >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Tips
- This approach depends on GitHub's availability and network connectivity. If you're on a company intranet or in a special network environment, make sure the server can access
github.comnormally. - Multi-platform support: Besides GitHub, GitLab also provides a similar feature, with the URL format
https://gitlab.com/用户名.keys. - Automated deployment: If you frequently tinker with servers, you can put the
curlcommand above into your initialization script or Dockerfile to achieve truly "frictionless" configuration.
_EOF_
Stop Manually Copying SSH Public Keys: One-Click Import from GitHub on Linux Servers
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
Debian配置默认不开启图形界面
前言 Linux的图形界面实在是太耗资源了,同时开几个虚拟机感觉已经hold不住了,赶紧把这些Linux服务器的图形界面都关掉。 CLI:command Line Interface,命令行界面。 现在的Linux发行版默认登陆界面几乎都是默认为GUI界面,如果按照旧版本的修改inittab文件,在一些比较新的版本是没有这个文件的(Linux的启动服务机制发生改变) 修改Grub配置文件 打开gr
2025-10-27 · 系统配置 · 约 1 分钟
内存不够用?在Linux上使用swapfile配置交换空间
前言 几个月前我还兴高采烈写了篇文章说给笔记本升级了内存配置,从乞丐版的4G一跃成为16G高富帅,然而,这几个月来我备受电脑死机的折磨,我现在有理由怀疑我可能买了假的内存条,于是没有办法,只能换回原厂的4G内存条,~~(然后准备赚部台式机)~~,问题不大。 换上4G内存条之后效果显著,只开了一个谷歌浏览器,内存占用就已经到了80%了,JB家的IDE是决计不敢再用了,可是这样还是难以满足系统对内存空
2025-10-27 · 系统配置 · 约 1 分钟
给VMware里的Linux虚拟机配置静态ip
前言 最近用VMware的时候是使用桥接方式,不知道是路由的问题还是其他,路由器里面没有显示虚拟机的连接,虽然虚拟机和主机都在路由器里分配了不同的IP地址,但是每次resume之后虚拟机的IP地址总是变,很麻烦。 VMware设置 把下面这个勾去掉。 然后点击Nat Settings。 记录网关。 虚拟机设置。把网络改成这个VMnet8。 Linux系统中配置静态IP Debian nano /e
2025-10-27 · 系统配置 · 约 1 分钟
Linux--使用Snap安装第三方微信客户端Electronic-Wechat
前言 腾讯估计是不会给Linux系统开发任何软件了,不过问题不大。我们有很多好用的第三方软件替代~~(无奈之举,摊手)~~ 关于Snap Ubuntu官网上的介绍 Snaps are applications packaged with all their dependencies to run on all popular Linux distributions from a single bu
2025-10-27 · 系统配置 · 约 1 分钟
讨论
共 0 条加载评论中…