SSH配置
生成密钥
bat
ssh-keygen -t rsa -b 2048默认保存到 C:\Users\<user>\.ssh\id_rsa,一路回车即可(可选设置 passphrase)。
查看公钥:
bat
type %USERPROFILE%\.ssh\id_rsa.pub拷贝公钥到目标机器
Linux 设备之间可使用 ssh-copy-id 拷贝公钥,在本机执行:
sh
ssh-copy-id -i ~/.ssh/id_rsa.pub user@host将 user 和 host 替换为目标机器的用户名和地址,按提示输入目标用户的密码,即可将本机公钥追加到目标机器的 ~/.ssh/authorized_keys。若公钥文件名不同,请替换 -i 后的路径。
Windows 没有 ssh-copy-id,用 type + ssh 替代:
bat
type %USERPROFILE%\.ssh\id_rsa.pub | ssh user@host "cat >> ~/.ssh/authorized_keys"验证免密登录:
bat
ssh user@host在 AGENTS.md 配置编译
AGENTS.md 可放在仓库任意目录,Agent 工作时会自动向上查找最近的 AGENTS.md,通常放在项目根目录。
(区别:.github/copilot-instructions.md 才是固定放在 .github/ 下的全局指令文件。)
AGENTS.md 示例(放仓库根目录):
markdown
## Build
- 构建命令:`make` 或 `cmake --build build/`
- 测试命令:`make test`
- 清理:`make clean`配置后,Agent 在执行编译相关任务时会自动使用上述命令,无需每次手动说明。
远程长时间执行与日志分析
tmux / screen(断开不中断)
SSH 断开后进程会被杀掉,用 tmux 保持会话:
sh
# 创建新会话
tmux new -s debug
# 在会话中执行长时间命令
./my_program
# 脱离会话(不中断程序):Ctrl+B, D
# 下次 SSH 登录后重新接入
tmux attach -t debug输出重定向到日志文件
sh
# stdout + stderr 都写入日志,同时在终端实时显示
./my_program 2>&1 | tee run.log
# 后台运行,日志写文件
nohup ./my_program > run.log 2>&1 &
echo $! # 打印 PID实时跟踪日志
sh
tail -f run.log过滤分析日志
sh
# 搜索关键字
grep -n "ERROR\|WARN" run.log
# 统计错误行数
grep -c "ERROR" run.log
# 查看最后 100 行
tail -n 100 run.log
# 按时间段截取(日志含时间戳)
awk '/10:00:00/,/10:05:00/' run.log从 Windows 侧分析日志
因目录是 Samba 共享,日志文件可直接在 Windows 工作区访问、用编辑器打开,无需额外拷贝。