生成命令
$ ssh-keygen -t ed25519 -C "your_email@example.com"
回车3次后生成
查看公钥
cat ~/.ssh/id_ed25519.pub
进入ssh页面:https://github.com/settings/keys(图1)
新建ssh秘钥,输入上一条命令的内容
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOgt4UBjUAMt2QLRrCkoFaBzJwsnIMWM6mLqNJUhb9V4 your_email@example.com
图1
SSH远程登录是站长的日常,使用密钥远程登录可以提高便捷性和服务器的安全性,首先从配置本地SSH密钥开始。
一、Window系统
1.1 新建ssh密钥
1、打开Terminal(Power Shell终端),使用ssh-keygen生成新密钥:
$ ssh-keygen -t ed25519 -C "your_email@example.com"
2、提示新密钥保存位置,直接回车保存到默认位置:%USERPROFILE%/.ssh/id_ed25519
Enter a file in which to save the key (/c/Users/you/.ssh/id_algorithm):[Press enter]
3、提示键入安全密码,直接回车不使用密码:
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
4、查看新密钥指纹:
$ cat ~/.ssh/id_ed25519
5、查看公钥
cat ~/.ssh/id_ed25519.pub
$ ssh-keygen -t ed25519 -C "your_email@example.com"
生成的文件夹
1.2 添加新密钥到ssh-agent
1、Window系统ssh-agent服务默认禁用,先把ssh-agent服务启动方式改为自启动。以管理员身份打开Terminal(Power Shell终端),输入:
Set-Service -Name ssh-agent -StartupType automatic
2、添加新密钥到ssh-agent:
$ ssh-add ~/.ssh/id_ed25519