简体   繁体   English

travis-ci - ssh-add询问我的密码

[英]travis-ci - ssh-add asking for my passphrase

I am working on a continuous integration with Travis CI. 我正在与Travis CI进行持续整合。 This is my configuration: 这是我的配置:

before_install:
  - echo -e "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
  - echo -e $id_rsa.pub > ~/.ssh/id_rsa.pub
  - echo -e $id_rsa > ~/.ssh/id_rsa
  - sudo chmod 600 ~/.ssh/*
  - sudo chmod 644 ~/.ssh/config
  - eval `ssh-agent -s`
  - ssh-add ~/.ssh/id_rsa
  ...

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/travis/.ssh/id_rsa: 

On the ssh-add step, it ask me the passphrase and it's stop the deployment. 在ssh-add步骤中,它会问我密码,它会停止部署。 I have tested with an other ssh key without passphrase but it don't fix my issue. 我已经使用其他ssh密钥进行了测试,但没有使用密码,但它并没有解决我的问题。

I have tested lot of solution like yes $MY_PASSWORD | ssh-add ~/.ssh/id_rsa 我已经测试了很多解决方案,比如yes $MY_PASSWORD | ssh-add ~/.ssh/id_rsa yes $MY_PASSWORD | ssh-add ~/.ssh/id_rsa or echo "$MY_PASSWORD" | ssh-add ~/.ssh/id_rsa yes $MY_PASSWORD | ssh-add ~/.ssh/id_rsaecho "$MY_PASSWORD" | ssh-add ~/.ssh/id_rsa echo "$MY_PASSWORD" | ssh-add ~/.ssh/id_rsa but it don't works. echo "$MY_PASSWORD" | ssh-add ~/.ssh/id_rsa但它不起作用。

I have added to my .ssh/config (you can see it in my config): 我已经添加到我的.ssh / config(你可以在我的配置中看到它):

Host *
    StrictHostKeyChecking no

isn't it supposed to make it don't ask me the passphrase ? 是不是应该让它不要问我密码?

Maybe someone have an idea ? 也许有人有想法? Thanks :) 谢谢 :)

You are using encrypted private key (which is good), but it needs the passphrase (which is bad for scripting). 您正在使用加密的私钥(这很好),但它需要密码(这对脚本来说是不好的)。 There are several possibilities you can proceed: 您可以继续进行以下几种方式:

  • Remove the passphrase from the key and use it unencrypted (less secure) 从密钥中删除密码并使用未加密的密码(不太安全)

     ssh-keygen -p -P "old_passphrase" -N "" -f ~/.ssh/id_rsa 
  • Use sshpass tool to unlock the key (storing the passphrase next to the key in the script basically defeats the security of encrypted key) 使用sshpass工具解锁密钥(在脚本中存储密钥旁边的密码短语基本上会破坏加密密钥的安全性)

     sshpass -p passphrase ssh-add ~/.ssh/id_rsa 

I had resolved my problem. 我解决了我的问题。 I had different problem in basic utilisation of environment variables and echo. 我在环境变量和回声的基本利用方面遇到了不同的问题。

  • My environment variables names were not good. 我的环境变量名称不好。 "$id_rsa.pub" in travis was interpreted by $id_rsa . travis中的“$ id_rsa.pub”由$ id_rsa解释。 ".pub" so it added some wrong characters to my content. “.pub”所以它为我的内容添加了一些错误的字符。 I renamed it to id_rsa_pub. 我将其重命名为id_rsa_pub。

  • I forget to transform " " in "\\ " and newlines by "\\n" and with travis and his environment variables, you must write "\\\\n" instead of just "\\n". 我忘了用“\\ n”转换“\\”和“\\ n”换行,用travis和他的环境变量,你必须写“\\\\ n”而不是“\\ n”。

My issue was in part because bad ssh files, and because I use a rsa key with password. 我的问题部分是因为糟糕的ssh文件,因为我使用带密码的rsa密钥。 In my case it's not important to have a password so i deleted it. 在我的情况下,拥有密码并不重要,所以我删除了它。 For that i use the answer of jakuje. 为此,我使用jakuje的答案。 My ssh key is now installed correctly in each builds. 我的ssh密钥现在已在每个版本中正确安装。

Thank you for your help ! 谢谢您的帮助 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM