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 许可协议。转载请注明出处!
相关文章
配置MariaDB数据库服务端远程访问
操作步骤 开启远程访问权限 连接MariaDB数据库,执行以下命令开启远程访问。 grant all privileges on *.* to 'root'@'192.168.248.248' identified by 'password'; flush privileges; 如果需要任意IP地址访问,就把IP地址换成%。 修改配置文件 在网络上能搜索到的资料都只说了第一点,然而亲测之后并没有
2025-10-27 · 系统配置 · 约 1 分钟
给你的Deepin系统换主题~
我现在的桌面: 因为美国封锁然后华为电脑用上Deepin系统的事情,Deepin系统最近名声大噪,其实Deepin本来的界面就很好看,号称打造最适合国人的系统不是盖的。 不过Deepin有一个坏处,就是默认主题的标题栏太大了…… 太占空间。所以我们要换主题折腾一下。 Deepin的桌面是Qt写的,所以首先要换KDE主题,然后再安排一下GTK3的主题,在Deepin系统设置里面换的主题就是GTK的,
2025-10-01 · 系统配置 · 约 1 分钟
小心误关了NAS服务器!修改Linux的电源键功能
NAS居然离线关机了?电源键被傻逼系统接管了。改改`logind.conf`让这玩意忽略电源键,省得误操作重启关机。谁用谁知道,别真当NAS是玩具。
2025-10-27 · 系统配置 · 约 1 分钟
内存不够用?在Linux上使用swapfile配置交换空间
前言 几个月前我还兴高采烈写了篇文章说给笔记本升级了内存配置,从乞丐版的4G一跃成为16G高富帅,然而,这几个月来我备受电脑死机的折磨,我现在有理由怀疑我可能买了假的内存条,于是没有办法,只能换回原厂的4G内存条,~~(然后准备赚部台式机)~~,问题不大。 换上4G内存条之后效果显著,只开了一个谷歌浏览器,内存占用就已经到了80%了,JB家的IDE是决计不敢再用了,可是这样还是难以满足系统对内存空
2025-10-27 · 系统配置 · 约 1 分钟
讨论
共 0 条加载评论中…