曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
系统配置

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.

曦远 (DealiAxy)约 6 分钟
目录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:

  1. Access https://github.com/username.keys via a network request.
  2. Retrieve the plaintext public key list returned by that page.
  3. Append these public keys to the corresponding user's ~/.ssh/authorized_keys file on the server.
  4. Ensure the .ssh directory and authorized_keys file have the correct permissions (usually 700 and 600).

How to Do It?

That Ubuntu feature actually invokes the ssh-import-id tool, which is also available in Debian's official repositories.

  1. Install the tool:

    Bash

    sudo apt update && sudo apt install ssh-import-id -y
    
  2. Import the public key:

    Bash

    ssh-import-id gh:你的GitHub用户名
    

    Note: The gh: prefix stands for GitHub; it also supports Launchpad (using lp:).

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.com normally.
  • 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 curl command 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 许可协议。转载请注明出处!

相关文章

给你的Deepin系统换主题~

我现在的桌面: 因为美国封锁然后华为电脑用上Deepin系统的事情,Deepin系统最近名声大噪,其实Deepin本来的界面就很好看,号称打造最适合国人的系统不是盖的。 不过Deepin有一个坏处,就是默认主题的标题栏太大了…… 太占空间。所以我们要换主题折腾一下。 Deepin的桌面是Qt写的,所以首先要换KDE主题,然后再安排一下GTK3的主题,在Deepin系统设置里面换的主题就是GTK的,

2025-10-01 · 系统配置 · 约 1 分钟

内存不够用?在Linux上使用swapfile配置交换空间

前言 几个月前我还兴高采烈写了篇文章说给笔记本升级了内存配置,从乞丐版的4G一跃成为16G高富帅,然而,这几个月来我备受电脑死机的折磨,我现在有理由怀疑我可能买了假的内存条,于是没有办法,只能换回原厂的4G内存条,~~(然后准备赚部台式机)~~,问题不大。 换上4G内存条之后效果显著,只开了一个谷歌浏览器,内存占用就已经到了80%了,JB家的IDE是决计不敢再用了,可是这样还是难以满足系统对内存空

2025-10-27 · 系统配置 · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…