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 许可协议。转载请注明出处!
相关文章
Ubuntu-18-04-修改登录界面背景图
前言 Ubuntu 18.04用了一段时间了,在Gnome桌面的加持下,兔子 18.04 的颜值还不错,加上自己搭配了几套GTK主题,简直美滋滋,唯一美中不足的就是,Ubuntu的登录管理器换成GDM之后,登录界面背景没办法修改了,这怎么行呢,于是经过一番折腾,有了本文。 首先,准备一张图片 图片的尺寸呢,根据你的屏幕分辨率确定咯。 然后把图片放到/usr/share/backgrounds/目录
2025-10-27 · 系统配置 · 约 1 分钟
Linux设置系统邮件转发到指定邮箱
前言 在Linux的操作中,有的时候每敲一下回车,就出来You have new mail in /var/spool/mail/root的提示,究竟是为什么呢? Linux 系统经常会自动发出一些邮件来提醒用户系统中出了哪些问题(收件箱位置:/var/mail/)。可是这些邮件都是发送给 root 用户的。出于系统安全考虑,通常不建议大家直接使用 root 帐户进行日常操作。所以要想点办法来让系
2025-10-27 · 系统配置 · 约 1 分钟
内存不够用?在Linux上使用swapfile配置交换空间
前言 几个月前我还兴高采烈写了篇文章说给笔记本升级了内存配置,从乞丐版的4G一跃成为16G高富帅,然而,这几个月来我备受电脑死机的折磨,我现在有理由怀疑我可能买了假的内存条,于是没有办法,只能换回原厂的4G内存条,~~(然后准备赚部台式机)~~,问题不大。 换上4G内存条之后效果显著,只开了一个谷歌浏览器,内存占用就已经到了80%了,JB家的IDE是决计不敢再用了,可是这样还是难以满足系统对内存空
2025-10-27 · 系统配置 · 约 1 分钟
Ubuntu-16-04-升级Python版本到3-6
前言 没办法,unity桌面实在是太好用了,Ubuntu18.04上安装了unity桌面毕竟不够完美,所以我昨天就降级到Ubuntu16.04,享受一波原生Unity桌面的快感。 一切都OK,不过Python版本有点低,所以要用万能PPA源升级一下。 操作 安装Python3.6 sudo add-apt-repository ppa:jonathonf/python-3.6 sudo apt-g
2025-10-27 · 系统配置 · 约 1 分钟
讨论
共 0 条加载评论中…