专业的编程技术博客社区

网站首页 > 博客文章 正文

生成新SSH密钥并添加到ssh-agent(ssh 生成)

baijin 2024-10-10 04:22:08 博客文章 13 ℃ 0 评论

SSH远程登录是站长的日常,使用密钥远程登录可以提高便捷性和服务器的安全性,首先从配置本地SSH密钥开始。

一、Window系统

1.1 新建ssh密钥

1、打开Terminal(Power Shell终端),使用ssh-keygen生成新密钥:

nbsp;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、查看新密钥指纹:

nbsp;cat ~/.ssh/id_ed25519

1.2 添加新密钥到ssh-agent

1、Window系统ssh-agent服务默认禁用,先把ssh-agent服务启动方式改为自启动。以管理员身份打开Terminal(Power Shell终端),输入:

Set-Service -Name ssh-agent -StartupType automatic

2、添加新密钥到ssh-agent:

nbsp;ssh-add ~/.ssh/id_ed25519

二、Linux或Mac系统

2.1 新建ssh密钥

1、打开终端,使用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 (/home/you/.ssh/algorithm): [Press enter]

3、提示键入安全密码,直接回车不使用密码:

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

4、查看新密钥指纹:

nbsp;cat ~/.ssh/id_ed25519

2.2 添加新秘钥到ssh-agent

1、启动ssh-agent服务:

nbsp;eval "$(ssh-agent -s)"

2、添加新密钥到ssh-agent:

nbsp;ssh-add ~/.ssh/id_ed25519

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表