SSH密钥-仍然要求密码和密码。

时间:2021-06-11 18:21:39

I've been somewhat 'putting up' with Github always asking for my username and password when I clone a repository. I want to bypass this step because it is an annoyance within my workflow.

当我克隆一个存储库时,我一直在“忍受”Github总是要求我的用户名和密码。我想绕过这一步,因为这是我工作流程中的一个烦恼。

I tried setting up an SSH key (which I successfully did) using this guide. https://help.github.com/articles/generating-ssh-keys and I was successful.

我尝试使用这个向导设置一个SSH密钥(我成功地做到了)。https://help.github.com/articles/generating-ssh-keys我是成功的。

My problem is that I am still asked for my github password and passphrase when cloning a repository (using SSH). My understanding was that after I set up this SSH key, I would no longer have to do that.

我的问题是,在克隆存储库(使用SSH)时,仍然需要我的github密码和密码。我的理解是,在我设置了这个SSH密钥之后,我就不再需要这样做了。

I am a little unsure what to ask, so I will just state my goal.

我有点不确定该问什么,所以我只说我的目标。

I want to be able to clone repositories without having to put in my Github information all the time.

我希望能够复制存储库,而不必一直使用Github信息。

What am I missing with my SSH key? If anyone can provide some guidance or resources I would appreciate it, because I've always felt a little lost when it came to SSH authentication in GitHub.

我的SSH密钥丢失了什么?如果有人能够提供一些指导或资源,我将非常感激,因为在GitHub上进行SSH认证时,我总是觉得有点失落。

From my knowledge, this is a command that tests if things are working properly, here are the output from my console:

根据我的知识,这是一个命令,如果测试工作正常,以下是我控制台的输出:

~ $ ssh -T git@github.com
Saving password to keychain failed
Enter passphrase for key '/Users/MYNAME/.ssh/id_rsa':
Hi MYNAME! You've successfully authenticated, but GitHub does not provide shell access.

When I input my password, should that fail first? Then, when I enter my passphrase, it passes.

当我输入我的密码时,应该先失败吗?然后,当我输入密码时,它就通过了。

16 个解决方案

#1


93  

If you work with HTTPs urls, it'll always ask for your username / password.

如果您使用的是HTTPs url,它总是会询问您的用户名/密码。

If you're correctly using SSH when cloning / setting remotes. Then make sure you have a ssh-agent to remember your password. That way, you'll only enter your passphrase once by terminal session.

如果您在克隆/设置remotes时正确使用SSH。然后确保你有一个ssh-agent来记住你的密码。这样,您只会在终端会话中输入您的密码。

If it is still too annoying, then simply set a ssh-key without passphrase.

如果它仍然太烦人,那么只需设置一个没有密码的ssh密钥。

#2


432  

Add Identity without Keychain

There may be times in which you don't want the passphrase stored in the keychain, but don't want to have to enter the passphrase over and over again.

有时,您可能不希望将密码存储在keychain中,但是不要一次又一次地输入密码。

You can do that like this:

你可以这样做:

ssh-add ~/.ssh/id_rsa 

This will ask you for the passphrase, enter it and it will not ask again until you restart.

这将要求您输入密码,输入它,在您重启之前它不会再问。

Add Identity Using Keychain

As @dennis points out in the comments, to persist the passphrase through restarts by storing it in your keychain, you can use the -K option when adding the identity like this:

正如@dennis在注释中指出的那样,要通过将密码存储在您的keychain中,来持久化passphrase,您可以在添加这样的标识时使用-K选项:

ssh-add -K ~/.ssh/id_rsa

Once again, this will ask you for the passphrase, enter it and this time it will never ask again for this identity.

再一次,这将要求你输入密码,输入它,这一次它不会再要求这个身份。

#3


172  

On Mac OSX you can add your private key to the keychain using the command:

在Mac OSX上,您可以使用以下命令将您的私钥添加到密钥链:

ssh-add -K /path/to/private_key

If your private key is stored at ~/.ssh and is named id_rsa:

如果您的私钥存储在~/。ssh并被命名为id_rsa:

ssh-add -K ~/.ssh/id_rsa

You will then be prompted for your password, which will be stored in your keychain.

然后将提示您输入密码,密码将存储在您的密钥链中。

#4


156  

I tried all the answers here and none of these answers worked! My password would not persist between sessions/restarts of my Mac.

我尝试了所有的答案,这些答案都没有奏效!我的密码不会在我的Mac的会话/重新启动之间持续。

What I found out from reading this OpenRadar and this Twitter discussion was that Apple purposely changed the behaviour for ssh-agent in macOS 10.12 Sierra to no longer automatically load the previous SSH keys. In order to maintain the same behaviour as El Cap I did the following:

我在阅读这个OpenRadar时发现,苹果故意改变了macOS 10.12 Sierra的SSH -agent的行为,不再自动加载之前的SSH密钥。为了保持与El Cap相同的行为,我做了如下工作:

  1. ssh-add -K ~/.ssh/id_rsa
    Note: change the path to where your id_rsa key is located.
  2. ssh-add - k ~ /。ssh/id_rsa注意:更改您的id_rsa密钥所在的路径。
  3. ssh-add -A
  4. ssh-add——
  5. Create (or edit if it exists) the following ~/.ssh/config file:

    创建(或编辑如果它存在)如下~/。ssh /配置文件:

    Host *
      UseKeychain yes
      AddKeysToAgent yes
      IdentityFile ~/.ssh/id_rsa
    

And now my password is remembered between restarts of my Mac!

现在我的密码被记住,在我的Mac重启!

#5


25  

Just run the following command:

只需运行以下命令:

ssh-add -K

It will never ask you to enter the password again.

它不会要求你再次输入密码。

#6


21  

You can remove passphrase for the key

您可以删除密钥的密码。

$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]

or you can run

或者您可以运行

$ ssh-keygen -p

you get a prompt for keyfile. By default it ~/.ssh/id_rsa so press enter

你会得到一个提示文件。默认情况下它~ /。ssh / id_rsa所以按回车

You'll be prompted for current pass phrase enter it.

你会被提示输入当前的密码。

Then there will be a prompt for new pass phrase, press enter

然后将会有一个新的传递短语的提示,按回车。

#7


10  

Make sure you are using ssh for your repository also

还要确保为存储库使用ssh。

mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v origin git@github.com:eMahtab/jenkins-cje-2017.git (fetch) origin git@github.com:eMahtab/jenkins-cje-2017.git (push)

mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font: minor - bidi ' > < / span > < span

SSH密钥-仍然要求密码和密码。

Don't use https, if your remote is using https then it will keep asking for password, even If you have added the public key to Github and added private key to ssh-agent. Below will always ask for password

不要使用https,如果你的遥控器使用https,那么它会一直要求密码,即使你已经将公钥添加到Github,并添加了私钥给ssh-agent。下面总是要求输入密码。

mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v origin https://github.com/eMahtab/jenkins-cje-2017.git (fetch) origin https://github.com/eMahtab/jenkins-cje-2017.git (push)

mso - hansi - font - family: tahoma; mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font:

#8


8  

Try ssh-agent as it is explained there : https://help.github.com/articles/working-with-ssh-key-passphrases

可以尝试使用ssh-agent: https://help.github.com/articles/workwith-ssh -key-passphrases。

#9


5  

For Mac OSX Sierra, I found that the fixes suggested in the github issue for Open Radar fixed my problem. Seems like Sierra changed the default behavior (I started having this problem after upgrading).

对于Mac OSX Sierra,我发现在github问题中建议的修复解决了我的问题。似乎Sierra改变了默认行为(我在升级后开始出现这个问题)。

This one I found especially useful: https://github.com/lionheart/openradar-mirror/issues/15361#issuecomment-249059061

我发现这一点特别有用:https://github.com/lionheart/openradar- mirror/states/15361 #发行:249059061。

ssh-add -A 

This resulted in my identity being added to the agent, after I ran

这导致在我运行之后,我的身份被添加到代理中。

ssh-add -K {/path/to/key}

To summarize, in OSX.12:

总而言之,在OSX.12:

ssh-add -K {/path/to/key}
ssh-add -A 

should result in:

会导致:

Identity added: {/path/to/file} ({/path/to/file})

EDIT: I noticed the next time I did a full reboot (aka the agent stopped and restarted) this no longer worked. The more complete solution is what @ChrisJF mentioned above: creating a ~/.ssh/config file. Here's the output of mine:

编辑:我注意到下一次我完全重新启动(也就是代理停止和重新启动)的时候,这不再起作用了。更完整的解决方案是@ChrisJF上面提到的:创建一个~/。ssh / config文件。这是我的输出:

$ cat ~/.ssh/config
Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa

You can add as many IdentityFile entries as you need, but this is the default setup. This is the "trending" answer on the openradar link above, ATM, as well.

您可以添加尽可能多的身份文件条目,但这是默认设置。这是上面的openradar链接的“趋势”答案,也就是ATM。

#10


3  

I already had set a passphrase but for some reason it wouldn't recognize it anymore. So I just added the identity file to my keychain again using ssh-add -K and it stopped asking for my password.

我已经设置了一个密码,但由于某种原因,它不再能识别了。所以我只是把身份文件添加到我的钥匙链中,再次使用ssh-add -K,它不再要求我的密码。

#11


2  

Use ssh remote url provided by Github not https.

使用Github提供的ssh远程url而不是https。

#12


2  

Problem seems to be because you're cloning from HTTPS and not SSH. I tried all the other solutions here but was still experiencing problems. This did it for me.

问题似乎在于,您是从HTTPS而不是SSH克隆的。我尝试了所有其他的解决方案,但仍然存在问题。这是为我做的。

Using the osxkeychain helper like so:

像这样使用osxkeychain助手:

  1. Find out if you have it installed.

    看看你是否安装了它。

    git credential-osxkeychain

    git credential-osxkeychain

  2. If it's not installed, you'll be prompted to download it as part of Xcode Command Line Tools.

    如果没有安装,将提示您将其下载为Xcode命令行工具的一部分。

  3. If it is installed, tell Git to use osxkeychain helper using the global credential.helper config:

    如果安装了,告诉Git使用全局凭证使用osxkeychain助手。辅助配置:

    git config --global credential.helper osxkeychain

    git配置——全球凭据。辅助osxkeychain

The next time you clone an HTTPS url, you'll be prompted for the username/password, and to grant access to the OSX keychain. After you do this the first time, it should be saved in your keychain and you won't have to type it in again.

下一次您克隆一个HTTPS url时,将提示您输入用户名/密码,并授予对OSX keychain的访问权。当你第一次做这个的时候,它应该被保存在你的钥匙链中,你就不用再输入它了。

#13


1  

If you're using windows, this worked for me:

如果你在使用windows,这对我很有用:

eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa

It'll ask for passphrase in the second command, and that's it.

它会在第二个命令中请求口令,就是这样。

#14


0  

If you are using ssh url for git, when prompted for password for ssh put the username as "git" and the password as your system's login password

如果您正在为git使用ssh url,当提示输入ssh密码时,将用户名称为“git”,并将密码作为系统的登录密码。

#15


0  

If you are using Windows and GIT without third party tools and your key is not secured by a password / passphrase use this:

如果您使用的是Windows和GIT,而没有第三方工具,您的密钥没有通过密码/口令来保护:

  1. Environment Variable HOME must be set to your user profile (e.g. C:\Users\Laptop)
  2. 环境变量HOME必须设置为您的用户配置文件(例如:c:users\ Laptop)
  3. Go to C:\Users\Laptop\.ssh\ folder and edit "config" file (or create the file!) Example: C:\Users\Laptop.ssh\config (note: there is no . at the end!)
  4. 去C:\Users\Laptop\.ssh\文件夹和编辑“config”文件(或创建文件!)例如:C:\Users\Laptop.ssh\config(注意:没有。最后!)
  5. Add your git-server host to the "config" file like so:

    将您的git-服务器主机添加到“config”文件中:

    #Example host entry
    Host myhostname.com
        HostName myhostname.com
        User git
        IdentityFile c:/users/laptop/.ssh/id_rsa.pub
        PasswordAuthentication no
        Port 422
    
  6. Save the file and clone the repository like this:

    保存文件并像这样复制存储库:

    git clone ssh://myhostname.com/git-server/repos/picalc.git

    git克隆ssh:/ /myhostname.com/git-server/repos/picalc.git

You can use additional configuration parameters for the "config" file host entry. These can be found in your local git installation folder, e.g. "C:\Program Files\Git\etc\ssh\ssh_config". Excerpt:

您可以为“config”文件主机条目使用额外的配置参数。这些可以在本地的git安装文件夹中找到。“C:\ Program Files \ Git \ etc \ ssh \ ssh_config”。摘录:

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h

#16


-1  

I'd like to add an answer for those who may still need to enter the password because they have set IdentitiesOnly as yes. This may cause by multiple keys and the identity file, being keys for git or server.

我想为那些可能仍然需要输入密码的人添加一个答案,因为他们已经设置了身份。这可能是由多个密钥和身份文件造成的,是git或服务器的密钥。

After I have generated the key and copied it to the server:

在我生成密钥并将其复制到服务器之后:

ssh-keygen
ssh-copy-id -i ~/.ssh/12gpu_server.pub lerner@192.168.20.160

I found it didn't work.

我发现它不起作用。

Then I went to check the ~/.ssh/config file, I saw this at the bottom:

然后我去查看~/。ssh/config文件,我在下面看到了:

Host *
IdentitiesOnly yes

Then I add this above:

然后我把这个加起来:

Host 12gpu
HostName 192.168.20.160
User lerner
IdentityFile ~/.ssh/12gpu_server

I can just log in by entering ssh 12gpu.

我可以通过输入ssh 12gpu来登录。

Then you can add multiple ssh keys using your favorite names, and you only need to add the settings like the above four lines to the config file.

然后,您可以使用您喜欢的名称添加多个ssh密钥,您只需要将这些设置添加到配置文件中。

Host is the name you'd like to enter when you connect to the server later; the HostName is the server's ip or domain like github.com; User is the user name you log in the server like the user name or git for github or gitlab; and the IdentityFile is the file where you store the key you have generated.

当您稍后连接到服务器时,主机名是您想要输入的名称;主机名是服务器的ip或域名,如github.com;用户是您在服务器上登录的用户名,比如github或gitlab的用户名或git;标识文件是存储生成的密钥的文件。

#1


93  

If you work with HTTPs urls, it'll always ask for your username / password.

如果您使用的是HTTPs url,它总是会询问您的用户名/密码。

If you're correctly using SSH when cloning / setting remotes. Then make sure you have a ssh-agent to remember your password. That way, you'll only enter your passphrase once by terminal session.

如果您在克隆/设置remotes时正确使用SSH。然后确保你有一个ssh-agent来记住你的密码。这样,您只会在终端会话中输入您的密码。

If it is still too annoying, then simply set a ssh-key without passphrase.

如果它仍然太烦人,那么只需设置一个没有密码的ssh密钥。

#2


432  

Add Identity without Keychain

There may be times in which you don't want the passphrase stored in the keychain, but don't want to have to enter the passphrase over and over again.

有时,您可能不希望将密码存储在keychain中,但是不要一次又一次地输入密码。

You can do that like this:

你可以这样做:

ssh-add ~/.ssh/id_rsa 

This will ask you for the passphrase, enter it and it will not ask again until you restart.

这将要求您输入密码,输入它,在您重启之前它不会再问。

Add Identity Using Keychain

As @dennis points out in the comments, to persist the passphrase through restarts by storing it in your keychain, you can use the -K option when adding the identity like this:

正如@dennis在注释中指出的那样,要通过将密码存储在您的keychain中,来持久化passphrase,您可以在添加这样的标识时使用-K选项:

ssh-add -K ~/.ssh/id_rsa

Once again, this will ask you for the passphrase, enter it and this time it will never ask again for this identity.

再一次,这将要求你输入密码,输入它,这一次它不会再要求这个身份。

#3


172  

On Mac OSX you can add your private key to the keychain using the command:

在Mac OSX上,您可以使用以下命令将您的私钥添加到密钥链:

ssh-add -K /path/to/private_key

If your private key is stored at ~/.ssh and is named id_rsa:

如果您的私钥存储在~/。ssh并被命名为id_rsa:

ssh-add -K ~/.ssh/id_rsa

You will then be prompted for your password, which will be stored in your keychain.

然后将提示您输入密码,密码将存储在您的密钥链中。

#4


156  

I tried all the answers here and none of these answers worked! My password would not persist between sessions/restarts of my Mac.

我尝试了所有的答案,这些答案都没有奏效!我的密码不会在我的Mac的会话/重新启动之间持续。

What I found out from reading this OpenRadar and this Twitter discussion was that Apple purposely changed the behaviour for ssh-agent in macOS 10.12 Sierra to no longer automatically load the previous SSH keys. In order to maintain the same behaviour as El Cap I did the following:

我在阅读这个OpenRadar时发现,苹果故意改变了macOS 10.12 Sierra的SSH -agent的行为,不再自动加载之前的SSH密钥。为了保持与El Cap相同的行为,我做了如下工作:

  1. ssh-add -K ~/.ssh/id_rsa
    Note: change the path to where your id_rsa key is located.
  2. ssh-add - k ~ /。ssh/id_rsa注意:更改您的id_rsa密钥所在的路径。
  3. ssh-add -A
  4. ssh-add——
  5. Create (or edit if it exists) the following ~/.ssh/config file:

    创建(或编辑如果它存在)如下~/。ssh /配置文件:

    Host *
      UseKeychain yes
      AddKeysToAgent yes
      IdentityFile ~/.ssh/id_rsa
    

And now my password is remembered between restarts of my Mac!

现在我的密码被记住,在我的Mac重启!

#5


25  

Just run the following command:

只需运行以下命令:

ssh-add -K

It will never ask you to enter the password again.

它不会要求你再次输入密码。

#6


21  

You can remove passphrase for the key

您可以删除密钥的密码。

$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]

or you can run

或者您可以运行

$ ssh-keygen -p

you get a prompt for keyfile. By default it ~/.ssh/id_rsa so press enter

你会得到一个提示文件。默认情况下它~ /。ssh / id_rsa所以按回车

You'll be prompted for current pass phrase enter it.

你会被提示输入当前的密码。

Then there will be a prompt for new pass phrase, press enter

然后将会有一个新的传递短语的提示,按回车。

#7


10  

Make sure you are using ssh for your repository also

还要确保为存储库使用ssh。

mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v origin git@github.com:eMahtab/jenkins-cje-2017.git (fetch) origin git@github.com:eMahtab/jenkins-cje-2017.git (push)

mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font: minor - bidi ' > < / span > < span

SSH密钥-仍然要求密码和密码。

Don't use https, if your remote is using https then it will keep asking for password, even If you have added the public key to Github and added private key to ssh-agent. Below will always ask for password

不要使用https,如果你的遥控器使用https,那么它会一直要求密码,即使你已经将公钥添加到Github,并添加了私钥给ssh-agent。下面总是要求输入密码。

mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v origin https://github.com/eMahtab/jenkins-cje-2017.git (fetch) origin https://github.com/eMahtab/jenkins-cje-2017.git (push)

mso - hansi - font - family: tahoma; mso - fareast - font - family:宋体;mso - bidi - font - family: " times new roman "; mso - bidi - theme - font:

#8


8  

Try ssh-agent as it is explained there : https://help.github.com/articles/working-with-ssh-key-passphrases

可以尝试使用ssh-agent: https://help.github.com/articles/workwith-ssh -key-passphrases。

#9


5  

For Mac OSX Sierra, I found that the fixes suggested in the github issue for Open Radar fixed my problem. Seems like Sierra changed the default behavior (I started having this problem after upgrading).

对于Mac OSX Sierra,我发现在github问题中建议的修复解决了我的问题。似乎Sierra改变了默认行为(我在升级后开始出现这个问题)。

This one I found especially useful: https://github.com/lionheart/openradar-mirror/issues/15361#issuecomment-249059061

我发现这一点特别有用:https://github.com/lionheart/openradar- mirror/states/15361 #发行:249059061。

ssh-add -A 

This resulted in my identity being added to the agent, after I ran

这导致在我运行之后,我的身份被添加到代理中。

ssh-add -K {/path/to/key}

To summarize, in OSX.12:

总而言之,在OSX.12:

ssh-add -K {/path/to/key}
ssh-add -A 

should result in:

会导致:

Identity added: {/path/to/file} ({/path/to/file})

EDIT: I noticed the next time I did a full reboot (aka the agent stopped and restarted) this no longer worked. The more complete solution is what @ChrisJF mentioned above: creating a ~/.ssh/config file. Here's the output of mine:

编辑:我注意到下一次我完全重新启动(也就是代理停止和重新启动)的时候,这不再起作用了。更完整的解决方案是@ChrisJF上面提到的:创建一个~/。ssh / config文件。这是我的输出:

$ cat ~/.ssh/config
Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa

You can add as many IdentityFile entries as you need, but this is the default setup. This is the "trending" answer on the openradar link above, ATM, as well.

您可以添加尽可能多的身份文件条目,但这是默认设置。这是上面的openradar链接的“趋势”答案,也就是ATM。

#10


3  

I already had set a passphrase but for some reason it wouldn't recognize it anymore. So I just added the identity file to my keychain again using ssh-add -K and it stopped asking for my password.

我已经设置了一个密码,但由于某种原因,它不再能识别了。所以我只是把身份文件添加到我的钥匙链中,再次使用ssh-add -K,它不再要求我的密码。

#11


2  

Use ssh remote url provided by Github not https.

使用Github提供的ssh远程url而不是https。

#12


2  

Problem seems to be because you're cloning from HTTPS and not SSH. I tried all the other solutions here but was still experiencing problems. This did it for me.

问题似乎在于,您是从HTTPS而不是SSH克隆的。我尝试了所有其他的解决方案,但仍然存在问题。这是为我做的。

Using the osxkeychain helper like so:

像这样使用osxkeychain助手:

  1. Find out if you have it installed.

    看看你是否安装了它。

    git credential-osxkeychain

    git credential-osxkeychain

  2. If it's not installed, you'll be prompted to download it as part of Xcode Command Line Tools.

    如果没有安装,将提示您将其下载为Xcode命令行工具的一部分。

  3. If it is installed, tell Git to use osxkeychain helper using the global credential.helper config:

    如果安装了,告诉Git使用全局凭证使用osxkeychain助手。辅助配置:

    git config --global credential.helper osxkeychain

    git配置——全球凭据。辅助osxkeychain

The next time you clone an HTTPS url, you'll be prompted for the username/password, and to grant access to the OSX keychain. After you do this the first time, it should be saved in your keychain and you won't have to type it in again.

下一次您克隆一个HTTPS url时,将提示您输入用户名/密码,并授予对OSX keychain的访问权。当你第一次做这个的时候,它应该被保存在你的钥匙链中,你就不用再输入它了。

#13


1  

If you're using windows, this worked for me:

如果你在使用windows,这对我很有用:

eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa

It'll ask for passphrase in the second command, and that's it.

它会在第二个命令中请求口令,就是这样。

#14


0  

If you are using ssh url for git, when prompted for password for ssh put the username as "git" and the password as your system's login password

如果您正在为git使用ssh url,当提示输入ssh密码时,将用户名称为“git”,并将密码作为系统的登录密码。

#15


0  

If you are using Windows and GIT without third party tools and your key is not secured by a password / passphrase use this:

如果您使用的是Windows和GIT,而没有第三方工具,您的密钥没有通过密码/口令来保护:

  1. Environment Variable HOME must be set to your user profile (e.g. C:\Users\Laptop)
  2. 环境变量HOME必须设置为您的用户配置文件(例如:c:users\ Laptop)
  3. Go to C:\Users\Laptop\.ssh\ folder and edit "config" file (or create the file!) Example: C:\Users\Laptop.ssh\config (note: there is no . at the end!)
  4. 去C:\Users\Laptop\.ssh\文件夹和编辑“config”文件(或创建文件!)例如:C:\Users\Laptop.ssh\config(注意:没有。最后!)
  5. Add your git-server host to the "config" file like so:

    将您的git-服务器主机添加到“config”文件中:

    #Example host entry
    Host myhostname.com
        HostName myhostname.com
        User git
        IdentityFile c:/users/laptop/.ssh/id_rsa.pub
        PasswordAuthentication no
        Port 422
    
  6. Save the file and clone the repository like this:

    保存文件并像这样复制存储库:

    git clone ssh://myhostname.com/git-server/repos/picalc.git

    git克隆ssh:/ /myhostname.com/git-server/repos/picalc.git

You can use additional configuration parameters for the "config" file host entry. These can be found in your local git installation folder, e.g. "C:\Program Files\Git\etc\ssh\ssh_config". Excerpt:

您可以为“config”文件主机条目使用额外的配置参数。这些可以在本地的git安装文件夹中找到。“C:\ Program Files \ Git \ etc \ ssh \ ssh_config”。摘录:

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h

#16


-1  

I'd like to add an answer for those who may still need to enter the password because they have set IdentitiesOnly as yes. This may cause by multiple keys and the identity file, being keys for git or server.

我想为那些可能仍然需要输入密码的人添加一个答案,因为他们已经设置了身份。这可能是由多个密钥和身份文件造成的,是git或服务器的密钥。

After I have generated the key and copied it to the server:

在我生成密钥并将其复制到服务器之后:

ssh-keygen
ssh-copy-id -i ~/.ssh/12gpu_server.pub lerner@192.168.20.160

I found it didn't work.

我发现它不起作用。

Then I went to check the ~/.ssh/config file, I saw this at the bottom:

然后我去查看~/。ssh/config文件,我在下面看到了:

Host *
IdentitiesOnly yes

Then I add this above:

然后我把这个加起来:

Host 12gpu
HostName 192.168.20.160
User lerner
IdentityFile ~/.ssh/12gpu_server

I can just log in by entering ssh 12gpu.

我可以通过输入ssh 12gpu来登录。

Then you can add multiple ssh keys using your favorite names, and you only need to add the settings like the above four lines to the config file.

然后,您可以使用您喜欢的名称添加多个ssh密钥,您只需要将这些设置添加到配置文件中。

Host is the name you'd like to enter when you connect to the server later; the HostName is the server's ip or domain like github.com; User is the user name you log in the server like the user name or git for github or gitlab; and the IdentityFile is the file where you store the key you have generated.

当您稍后连接到服务器时,主机名是您想要输入的名称;主机名是服务器的ip或域名,如github.com;用户是您在服务器上登录的用户名,比如github或gitlab的用户名或git;标识文件是存储生成的密钥的文件。