[{"data":1,"prerenderedAt":244},["ShallowReactive",2],{"content:\u002F2023\u002Fssh-key-login":3,"surround:\u002F2023\u002Fssh-key-login":233},{"id":4,"title":5,"body":6,"categories":205,"date":207,"description":208,"draft":209,"extension":210,"image":211,"meta":212,"navigation":214,"path":215,"permalink":216,"published":216,"readingTime":217,"recommend":222,"references":216,"seo":223,"sitemap":224,"stem":225,"tags":226,"type":230,"updated":231,"__hash__":232},"content\u002Fposts\u002F2023\u002Fssh-key-login.md","SSH 免密登录",{"type":7,"value":8,"toc":193},"minimark",[9,13,20,25,28,32,52,55,62,70,84,94,98,106,115,118,122,131,136,139,149,156,162,165,183,187],[10,11,12],"p",{},"在终端中使用 SSH 之前，可以先美化终端以提升用户体验。",[14,15],"link-banner",{"banner":16,"description":17,"link":18,"title":19},"https:\u002F\u002Fassets.zhilu.cyou\u002Fcover3\u002Fwindows-terminal.jpg","一篇优化 Windows Terminal 体验的指南，涵盖 PowerShell 增强、Oh My Posh 主题配置、集成 Git Bash 以及终端美化等方面。","\u002F2024\u002Fwindows-terminal","Windows 终端体验优化指南",[21,22,24],"h2",{"id":23},"生成ssh密钥","生成SSH密钥",[10,26,27],{},"ED225519 类型的密钥综合性能更好。",[29,30],"copy",{"code":31},"ssh-keygen -t ed25519",[10,33,34,35,42,43,47,48,51],{},"连续按回车键即可。如果你想自定义生成内容，请使用 ",[36,37,40],"code",{"className":38,"code":40,"language":41},[39],"language-sh","ssh-keygen -t ed25519 -C \"内容\"","sh","。生成好的",[44,45,46],"strong",{},"公钥","可以通过 ",[36,49,50],{"code":50},"cat ~\u002F.ssh\u002Fid_ed25519.pub"," 查看。",[21,53,54],{"id":54},"将公钥加入认证列表",[10,56,57,58,61],{},"如果服务端是 Windows OpenSSH，请将服务端 ",[36,59,60],{"code":60},"%ProgramData%\\ssh\\sshd_config"," 文件中的此行取消注释（需要管理员权限）：",[63,64,68],"pre",{"className":65,"code":66,"filename":60,"language":41,"meta":67},[39],"# PubkeyAuthentication yes\n","",[36,69,66],{"__ignoreMap":67},[10,71,72,73,76,77,79,80,83],{},"在 ",[36,74,75],{"code":75},"~\u002F.ssh\u002Fauthorized_keys"," 文件中逐行添加",[44,78,46],{},"即可。此文件的权限应当是 ",[36,81,82],{"code":82},"644","，否则可能会被拒绝读取（也就是无法用SSH公钥认证登录）。",[10,85,86,87],{},"示例：",[88,89,93],"a",{"href":90,"rel":91},"https:\u002F\u002Fgist.github.com\u002FL33Z22L11\u002Ffdac255fe90aa9677bf530e7792db703",[92],"nofollow","我的SSH公钥",[21,95,97],{"id":96},"避免每次输入用户名和ip地址","避免每次输入用户名和IP地址",[10,99,100,101,105],{},"如果你有经常连接的 SSH 服务器，可以在 SSH 配置文件中按照以下格式添加条目，即可直接通过 Host 项的名字连接，还能在 ",[36,102,104],{"className":103,"code":104,"language":41},[39],"ssh"," 命令输到一半时按 Tab 键自动补全：",[63,107,113],{"className":108,"code":110,"filename":111,"language":112,"meta":67},[109],"language-ssh-config","Host zhilu-server\n    Hostname 1.1.1.1\n    Port 8022\n    User zhilu\n","~\u002F.ssh\u002Fconfig","ssh-config",[36,114,110],{"__ignoreMap":67},[10,116,117],{},"在 SSH 配置文件中，缩进是一个 Tab 或者 4 个空格。（早期 CMake 的惯用缩进 8 个空格作为规范）",[21,119,121],{"id":120},"使用公钥完成-github-登录","使用公钥完成 GitHub 登录",[10,123,124,125,130],{},"参见 GitHub 官方教程：",[88,126,129],{"href":127,"rel":128},"https:\u002F\u002Fdocs.github.com\u002Fzh\u002Fauthentication\u002Fconnecting-to-github-with-ssh",[92],"通过 SSH 连接到 GitHub","。",[132,133,135],"h3",{"id":134},"设置-ssh-代理","设置 SSH 代理",[10,137,138],{},"通常不建议使用 HTTPS 连接到 GitHub，通过 SSH 连接时一般不需要代理即可直接访问。如果没有使用“TUN 模式”或透明代理，系统代理设置不会自动应用到 SSH 连接上。",[140,141,142],"ul",{},[143,144,145,146],"li",{},"更改仓库的远程地址\n",[29,147],{"code":148},"git remote set-url origin git@github.com:username\u002Frepo.git",[10,150,151,152,155],{},"当使用代理时，大多数节点",[44,153,154],{},"不允许直接访问 22 端口","，因此应在 443 端口通过 SSH 连接到 GitHub 仓库。可以通过修改 SSH 配置文件实现：",[63,157,160],{"className":158,"code":159,"filename":111,"language":112,"meta":67},[109],"Host github.com\n    Hostname ssh.github.com\n    Port 443\n    User git\n    # TUN 模式或透明代理不需要 ProxyCommand\n    # Windows下SOCKS5\n    # ProxyCommand connect -S 127.0.0.1:10808 %h %p\n    # Windows下HTTP\n    # ProxyCommand connect -H 127.0.0.1:10809 %h %p\n    # Linux和macOS下SOCKS5\n    # ProxyCommand nc -v -x 127.0.0.1:20170 %h %p\n    # Linux和macOS下HTTP\n    # ProxyCommand nc -v -X connect -x 127.0.0.1:20172 %h %p\n",[36,161,159],{"__ignoreMap":67},[10,163,164],{},"这样一般能正常执行 git 操作，如果不行，可以通过启用或取消注释来通过代理访问 GitHub，端口可能需要更改。",[140,166,167,175],{},[143,168,169,170,174],{},"Linux 和 macOS：可以使用 ",[36,171,173],{"className":172,"code":173,"language":41},[39],"nc"," 工具来实现 SOCKS5 代理。",[143,176,177,178,182],{},"Windows：需要用 ",[36,179,181],{"className":180,"code":181,"language":41},[39],"connect"," 命令，该命令可在 Git for Windows 提供的 Git Bash 中找到，如果无法执行 connect，可能需要使用 Git Bash 操作。",[21,184,186],{"id":185},"关于-ssh-的更多玩法","关于 SSH 的更多玩法",[188,189],"link-card",{"icon":190,"link":191,"title":192},"https:\u002F\u002Fcdn.yuuu.org\u002Fimg\u002Ffavicon-192x192.png","https:\u002F\u002Fyuuu.org\u002Fpost\u002F64202.html","ssh 知识整理 | 微霞",{"title":67,"searchDepth":194,"depth":194,"links":195},4,[196,198,199,200,204],{"id":23,"depth":197,"text":24},2,{"id":54,"depth":197,"text":54},{"id":96,"depth":197,"text":97},{"id":120,"depth":197,"text":121,"children":201},[202],{"id":134,"depth":203,"text":135},3,{"id":185,"depth":197,"text":186},[206],"技术","2023-12-25 16:15:00","生成SSH密钥，启用公钥认证，将公钥添加至授权列表，实现 Windows\u002FLinux\u002FGitHub SSH 免密登录。",false,"md","https:\u002F\u002Fassets.zhilu.cyou\u002Fcover3\u002Fssh-key-login.jpg",{"slots":213},{},true,"\u002F2023\u002Fssh-key-login",null,{"text":218,"minutes":219,"time":220,"words":221},"4 min read",3.06,183600,612,1,{"title":5,"description":208},{"loc":215},"posts\u002F2023\u002Fssh-key-login",[227,228,229],"SSH","免密登录","远程访问","tech","2024-12-26 20:32:04","IFYRYVKhpnxW57L_lfRup3eScNeMqNNiDkdwNRkmLsk",[234,239],{"title":235,"path":236,"stem":237,"date":238,"type":230,"children":-1},"xv6 lab环境配置","\u002F2023\u002Fxv6-lab-setup","posts\u002F2023\u002Fxv6-lab-setup","2023-11-20 17:09:28",{"title":240,"path":241,"stem":242,"date":243,"type":230,"children":-1},"Moonlight 串流指南","\u002F2024\u002Fmoonlight-streaming-guide","posts\u002F2024\u002Fmoonlight-streaming-guide","2024-01-18 18:58:55",1782091373634]