atuin:跨机器同步 + 加密的 shell 历史

起因

shell 历史的痛点:

  • 几台机器(笔记本 / 台式 / 远程 server)历史不互通
  • Ctrl-R 反搜慢 + 一次显一条
  • 历史没 metadata(哪个目录跑的?exit code?耗时?)
  • 关闭终端 history 偶尔丢

atuin 是 Rust 写的 shell history 替代:

  • 历史存 SQLite,带元数据(cwd、exit、duration、host、session)
  • E2E 加密同步到 server(自己 host 或官方)
  • Ctrl-R 替换成全屏 fuzzy search UI

brew install atuin
curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh

# shell 集成
atuin init zsh >> ~/.zshrc
atuin init bash >> ~/.bashrc
atuin init fish | source

import 现有历史:

atuin import auto      # 检测 shell 自动 import

第一次用

Ctrl-R 启动 atuin 全屏 search:

 atuin search ~/proj/myapp ────────────────────────────────────────
> docker

  10s    /home/u/proj         docker compose up -d                ✓
  2m     /home/u/other-proj   docker logs api -f                  ✓
  1h     /home/u/proj         docker compose ps                   ✓
  yesterday /home/u/proj      docker compose build                ✓

────────────────────────────────────────────────────────────────────
filter <ctrl-r> | invert <ctrl-a> | exit <esc>
  • 实时 fuzzy 过滤
  • 显示运行时间 / cwd / 是否成功(✓/✗)
  • enter 执行 / tab 编辑

Ctrl-R 一秒查 10 年前在哪台机器跑过啥命令。

sync 同步

注册账号:

atuin register -u me -e [email protected]
atuin login -u me

# import 上来的 + 之后的命令都加密同步到 cloud

E2E 加密:服务端只存 ciphertext,端上解密。
默认用 atuin.sh 官方服务(免费);介意 → 自部署:

docker run -d -p 8888:8888 ghcr.io/atuinsh/atuin server start

~/.config/atuin/config.toml

sync_address = "https://your-server.com"

跨机器登录

新机器:

brew install atuin
atuin login -u me -p <password> -k <encryption-key>
atuin sync

-k 是首次注册时 atuin 显示的加密 key,自己存好(atuin
server 无法恢复 key)。

atuin sync 把云端历史拉下来 + 解密 → 立刻有所有机器的命令。

配置过滤

不想同步某些命令:

# ~/.config/atuin/config.toml

# 不记录 secret 命令
history_filter = [
    "^secret-cmd",
    "^aws.*--secret",
]

# 不在公共 wifi 同步
sync_address = "..."
auto_sync = true
sync_frequency = "5m"

stats

$ atuin stats

Top commands:
 1. git status      (1234)
 2. ls              (987)
 3. cd ..           (876)
 ...

Total commands: 45678
First command: 2022-03-14

或者:

$ atuin stats day
$ atuin stats week
$ atuin stats --since '1 month ago'

看一个月你跑啥最多。会启发优化 alias / 工作流。

各机器 history 分别看

atuin search --cwd .            # 当前目录历史
atuin search --hostname laptop  # 在 laptop 跑的
atuin search --exit 0           # 只成功的
atuin search 'docker' --before '1 week ago'

内置 vs atuin

shell 内置 history atuin
存储 ~/.zsh_history (text) SQLite
同步 跨机器加密
元数据 cwd / exit / duration
搜索 反搜(单行) TUI fuzzy
容量 几千-几万行 无限
性能 文件 grep 索引 query

不会用 atuin 后就回不去了。

性能

atuin search 上百万 history entry sub-50ms 响应。SQLite 索引 +
Rust 解析快。

启动开销:shell 集成 ~5-10ms(vs no atuin ~0ms)。基本无感。

替代品

  • mcfly(rust):类似 atuin,没 sync
  • hstr:传统 TUI,无元数据
  • fzf + fc:fzf 模糊搜历史(无元数据)

atuin 是目前最完整方案。

退出策略

万一不喜欢:

# 取消 shell 集成(从 .zshrc 删 atuin init)
# 导出回 plain history
atuin export csv > history.csv

# 删 SQLite
rm -rf ~/.local/share/atuin

history 不会"绑定"住你。

隐私 / 安全

  • 数据库本地:~/.local/share/atuin/history.db,未加密 → 笔记本被偷
    对方能读历史
  • 云端:E2E 加密,server 看不到内容
  • 命令含 secret:history_filter 排除

担心本地泄密 → FileVault / LUKS 全盘加密 + atuin filter sensitive 命令。

一个 case:debug 老问题

3 个月后客户报"上次配的某个 nginx 设置不工作了"。
我不记得当时改了啥。

$ atuin search --since '4 months ago' --before '2 months ago' nginx

10 个命令列出来:当时 edit 啥配置、reload、看 log。
2 分钟还原情境。比"翻 commit / 看 wiki"快多了。

shell history 是被低估的 personal knowledge base。

踩过的坑

  1. 首次同步慢:百万 entry 上传几分钟。耐心等。

  2. 重复 history:bash + zsh 都用 atuin → 同命令记两次。每 shell
    只用一个。

  3. 导入 fish 历史 format 不对:fish 用 yaml 历史,老版本 atuin
    import 解析坑。新版本修了。

  4. Up 键被吃:atuin 默认绑 Up 显示历史 → 跟 vi mode 冲突。
    disable_up_arrow = true 关。

  5. 加密 key 丢了:服务端有数据但解密不了。atuin register
    立刻把 key 存密码管理器

精确评价 共 0 人评价
可复现性
可复现 · 0 不可复现 · 0
文风
文风流畅 · 0 文风晦涩 · 0
立场
支持 · 0 反对 · 0

登录后即可对本帖作出评价。

评论区 0 条 · 所有人可在此交流

登录后参与评论。

还没有评论,来说两句。