如何生成 ssh 密钥(用于 github)
问题:如何使用命令行生成 ssh 私钥和公钥(在 GitHub/GitLab 中使用)。
以下命令会生成错误
sh.exe": syntax error near unexpected token '('
“我正在使用 Windows XP”。
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/xxxx/.ssh/id_rsa.
Your public key has been saved in /c/Users/xxxx/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
Question: How do I generate ssh private and public keys (to be used in GitHub/GitLab) using command line.
The command below generates the error
sh.exe": syntax error near unexpected token '('
I am using Windows XP.
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxx/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/xxxx/.ssh/id_rsa.
Your public key has been saved in /c/Users/xxxx/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要运行的命令只是
脚本的第 2 行开始的所有其余内容都是 ssh-keygen 的输出。
并将 [email protected] 替换为您的电子邮件地址。
查看
ssh-keygen
手册寻找额外的选择。您可能应该通过将-b 4096
添加到选项列表来使用更长的密钥。The command to run is only
All the rest beginning with line 2 of your script is the output of ssh-keygen.
And replace [email protected] with your email address.
Have a look at the manual for
ssh-keygen
to look for additional options. You should probably use a longer key by adding-b 4096
to the option list.这是命令
这将为您生成一个密钥。你必须复制它并插入到你的 Github 帐户中(只需一次)。
操作步骤
Here is the command
This will generate a key for you. You have to copy that and insert into your Github's account (just one time).
Steps how to do It
第 1 步:生成 SSH 密钥
第 2 步:使用密钥
然后添加我们刚刚生成的密钥。如果您选择的路径与默认路径不同,请务必替换命令中的该路径。
第 3 步:在 GitHub 上添加 SSH 密钥
如果找不到剪辑,则添加下一个命令
最终结果类似于您的 cmd
从您的 cmd 复制并转到您的 GitHub 帐户
设置查找 ssh 和 gpg 密钥
Step 1: Generate Your SSH Key
Step 2: Use the Key
Then add the key we just generated. If you selected a different path than the default, be sure to replace that path in the command.
Step 3: Add the SSH Key on GitHub
if clip not found then add the next command
Finally Result something like on your cmd
copy from your cmd and go to your GitHub account
setting find ssh and gpg keys
使用下面的命令生成 SSH 密钥,
只需按 Enter 键即可为其要求的所有输入应用默认值,
输出将
只需使用
cat
命令在终端上记录 ssh 密钥文件内容(使用您自己的路径在这里)。输出将为
ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [email protected]
复制内容并转到您的 github 帐户,转到帐户设置>SSH 和 GPG 密钥下的设置,单击
新 SSH 密钥
,提供您想要的名称,然后将复制的内容粘贴到值中并保存。就这样,您就可以提交更改,而无需每次都使用用户名和密码。Generate SSH key using below command
just hit enter to apply the default value for all the inputs it asks
the output will be
just use the
cat
command to log the ssh key file contents on the terminal(use your own path here).the output will be
ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [email protected]
copy the contents and go to your github account go to settings under Account settings>SSH and GPG keys click on
New SSH key
, provide the name you wish and paste the copied contents in the value and save. that's it you are ready to commit your changes without using username, password every time.只需应用两个命令:
ssh-keygen -t rsa -b 4096
cat ~/.ssh/id_rsa.pub
复制 ssh 密钥并粘贴到浏览器上
转到 home/.ssh文件夹。单击配置文件并添加这两行(如果配置文件不存在,则创建一个名为“config”的文件)
HostKeyAlgorithms ssh-rsa
PubkeyAcceptedKeyTypes ssh-rsa
Just apply two commands :
ssh-keygen -t rsa -b 4096
cat ~/.ssh/id_rsa.pub
Copy ssh key and paste on browser
Go to home/.ssh folder. Click on config file and add these two line(if config file doesn't exist then create a file name as "config")
HostKeyAlgorithms ssh-rsa
PubkeyAcceptedKeyTypes ssh-rsa
解决方案:
ssh-keygen -t rsa
说明:
ssh-keygen
是一个用于创建新的身份验证密钥对的工具用于 SSH。此类密钥对用于自动登录、单点登录和验证主机(例如,将项目从 Github 上的私人存储库直接克隆到您的 AWS 计算机)。
选项:您可以执行更复杂的操作并使用标志来根据您的用例生成量身定制的密钥,扩展功能更加强大和安全。基本标志是:
bits
(大整数使 RSA 密钥不易受到攻击且难以破解)、passphrase
(类似于密码)、type
code> (dsa/ecdsa/ed25519/rsa) ,特定 ssh 令牌(电子邮件或用户名)的comment
和output key
(默认存储在 ~/.ssh/路径)概要:
ssh-keygen [-q] [-b 位] [-t dsa | 路径] ECDSA | ed25519 | rsa] [-N new_passphrase] [-C comment] [-f output_keyfile]
示例:
Solution:
ssh-keygen -t rsa
Explanation :
ssh-keygen
is a tool for creating new authentication key pairs for SSH. Such key pairs are used for automating logins, single sign-on, and for authenticating hosts(for example cloning project from your private repo on Github straight to your aws machine).
Options: You can perform more complicated operations and using flags in order to generate a tailor-made key according to your use case, extended functionality are more powerful and secured. The basic flags are:
bits
(Large integers making the the RSA key be less vulnerable and hard to crack),passphrase
(similar to password) ,type
(dsa/ecdsa/ed25519/rsa) ,comment
for the specific ssh token (email or user name) andoutput key
(default store on ~/.ssh/ path)Synopsis:
ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa] [-N new_passphrase] [-C comment] [-f output_keyfile]
Example: