From 7c52431fb1b625cdb64d11efd37fc94752507f0f Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 5 Feb 2026 15:45:36 +0800 Subject: docs: new notes --- content/notes/ghostty-ssh-issue.md | 41 +++++++++++++++++++++++++++++++++ content/notes/reinforce-vps.md | 46 ------------------------------------- content/notes/ssh-keys-over-pswd.md | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 46 deletions(-) create mode 100644 content/notes/ghostty-ssh-issue.md delete mode 100644 content/notes/reinforce-vps.md create mode 100644 content/notes/ssh-keys-over-pswd.md diff --git a/content/notes/ghostty-ssh-issue.md b/content/notes/ghostty-ssh-issue.md new file mode 100644 index 0000000..45c82ac --- /dev/null +++ b/content/notes/ghostty-ssh-issue.md @@ -0,0 +1,41 @@ ++++ +title = "在 Ghostty 中使用 SSH 的问题" +date = 2026-02-05 15:44:45 +tags = ["运维", "Linux"] ++++ + +## 问题描述 + +我的主力终端模拟器是 [Ghostty](https://ghostty.org/),直接 SSH 到远程服务器可能遇到一些问题,比如无法打开 `htop`、使用 `systemctl` 查看服务的状态时会提示终端 `not fully functional`,一些颜色的显示也会有问题。 + +调查后发现原因来自 Ghostty 的 Terminfo(终端信息)。简单来说,Terminfo 是一种很老的格式,许多终端应用会通过读取 Terminfo 来确定终端的能力;如果应用程序不认识这个终端,可能会认为当前运行程序的终端缺少必要的能力,继而无法正常运行。 + +Ghostty 的终端信息是 `xterm-ghostty`,如果 SSH 到一台没有 Ghostty 的终端信息条目的机器上,可能会得到这样的提示: + +```shell +missing or unsuitable terminal: xterm-ghostty +Error opening terminal: xterm-ghostty. +WARNING: terminal is not fully functional +``` + +## 解决方案 + +根据 Ghossty 的文档,解决方案有两个,我使用的方法是修改环境变量,把 `TERM` 设置为另一个被广泛支持的终端,比如 `xterm-256color`。可以在 `.ssh/config` 里这样写。 + +``` +Host example + TERM=xterm-256color +``` + +这样远程服务器就会把 Ghostty 视作 256color,不会认为 Ghostty 缺少某些功能。 + +还有一种方法是把 Ghostty 的信息发送到远程服务器上。 + +```shell +infocmp -x xterm-ghostty | ssh YOUR-SERVER -- tic -x - +``` + +## 参考资料 + +- https://ghostty.org/docs/help/terminfo#ssh +- https://en.wikipedia.org/wiki/Terminfo diff --git a/content/notes/reinforce-vps.md b/content/notes/reinforce-vps.md deleted file mode 100644 index a7c4f9c..0000000 --- a/content/notes/reinforce-vps.md +++ /dev/null @@ -1,46 +0,0 @@ -+++ -title = "加固 VPS:密钥替代密码" -date = 2026-01-26T14:57:33Z -tags = ["运维", "Linux"] -+++ - -购置了 Contabo VPS,想要在服务器层面加固防护,遂做此笔记。 - -## 1. 配置 SSH 密钥登录 - -在本地生成一对 SSH 密钥对,使用 ed25519 算法而非老旧的 RSA。 - -```shell -ssh-keygen -t ed25519 -``` - -密钥默认保存在 `~/.ssh/id_ed25519`,可以更改位置。生成过后,需要将公钥放到服务器上,具体的原理在此不赘述。最方便的做法是使用 `ssh-copy-id`,如下: - -```shell -ssh-copy-id @ -``` - -SSH 登录到 VPS,测试能否使用保存在本地的 SSH 密钥直接登录。如果在 `ssh-keygen` 时设置了 Passphrase,此时也需要输入 Passphrase 才能登录。如果觉得麻烦,可以使用 `ssh-agent`。 - -```shell -eval "$(ssh-agent -s)" -ssh-add ~/.ssh/id_ed25519 # 之后会要求输入 Passphrase -``` - -然后再次 SSH 登录到服务器测试,看看能否不输入 Passphrase 直接登录。最后,要保存好 SSH 密钥,最好离线备份在移动硬盘里,或者重复上述步骤生成一个备用密钥放在别处。 - -## 2. 禁用密码登录和 Root 登录 - -密码登录很容易被暴力破解,能够用 SSH 密钥登录之后最好禁用密码登录。这一步要额外小心,不然有可能被锁在服务器外面。 - -修改服务器上的 SSH 配置: - -```shell -vim /etc/ssh/sshd_config -``` - -找到 `PasswordAuthentication`(允许密码认证)和 `PermitRootLogin`(允许 Root 登录),删掉前面的 `#` 注释,把 `yes` 改成 `no`。保存,然后 `sudo systemctl restart ssh`。 - -## 参考 - -- https://blog.eimoon.com/p/ubuntu-ssh-key-setup-guide/ diff --git a/content/notes/ssh-keys-over-pswd.md b/content/notes/ssh-keys-over-pswd.md new file mode 100644 index 0000000..a7c4f9c --- /dev/null +++ b/content/notes/ssh-keys-over-pswd.md @@ -0,0 +1,46 @@ ++++ +title = "加固 VPS:密钥替代密码" +date = 2026-01-26T14:57:33Z +tags = ["运维", "Linux"] ++++ + +购置了 Contabo VPS,想要在服务器层面加固防护,遂做此笔记。 + +## 1. 配置 SSH 密钥登录 + +在本地生成一对 SSH 密钥对,使用 ed25519 算法而非老旧的 RSA。 + +```shell +ssh-keygen -t ed25519 +``` + +密钥默认保存在 `~/.ssh/id_ed25519`,可以更改位置。生成过后,需要将公钥放到服务器上,具体的原理在此不赘述。最方便的做法是使用 `ssh-copy-id`,如下: + +```shell +ssh-copy-id @ +``` + +SSH 登录到 VPS,测试能否使用保存在本地的 SSH 密钥直接登录。如果在 `ssh-keygen` 时设置了 Passphrase,此时也需要输入 Passphrase 才能登录。如果觉得麻烦,可以使用 `ssh-agent`。 + +```shell +eval "$(ssh-agent -s)" +ssh-add ~/.ssh/id_ed25519 # 之后会要求输入 Passphrase +``` + +然后再次 SSH 登录到服务器测试,看看能否不输入 Passphrase 直接登录。最后,要保存好 SSH 密钥,最好离线备份在移动硬盘里,或者重复上述步骤生成一个备用密钥放在别处。 + +## 2. 禁用密码登录和 Root 登录 + +密码登录很容易被暴力破解,能够用 SSH 密钥登录之后最好禁用密码登录。这一步要额外小心,不然有可能被锁在服务器外面。 + +修改服务器上的 SSH 配置: + +```shell +vim /etc/ssh/sshd_config +``` + +找到 `PasswordAuthentication`(允许密码认证)和 `PermitRootLogin`(允许 Root 登录),删掉前面的 `#` 注释,把 `yes` 改成 `no`。保存,然后 `sudo systemctl restart ssh`。 + +## 参考 + +- https://blog.eimoon.com/p/ubuntu-ssh-key-setup-guide/ -- cgit v1.2.3