致命错误:无法读取'https://github.com'的用户名:没有此设备或地址。

10

我已经使用github和capistrano将我的Rails 4应用程序部署到了Rackspace上几个星期了。一切都很正常,直到我最终将我的代码库设为私有。现在,在运行“cap deploy”后,我收到以下错误:

"fatal: could not read Password for 'https://username@github.com': No such device or address"

以下是我的deploy.rb文件中的代码:

set :application, "appname"
set :repository,  "https://git_username@github.com/git_username/appname.git"
set :scm, :git
set :scm_username, "git_username"
set :scm_passphrase, "git_password"
set :scm_command, "git"
set :keep_releases, 5
set :branch, "master"
set :rails_env, "production"

set :deploy_to, "/var/www/doLocal"

set :user, "deployer"
set :password, "deployer_password"
set :use_sudo, false

ssh_options[:forward_agent] = true

server "/path/to/server", :app, :web, :db, :primary => true

after "deploy:restart", "deploy:cleanup"


namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
     run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

我已尝试在 github 仓库名称前加上用户名和不加用户名两种方式,如果加了用户名,则会收到上述密码错误的错误信息,而如果不加用户名,则会收到以下错误信息:

"fatal: could not read Username for 'https://github.com': No such device or address"

您有什么想法?我猜这可能与我更改为私有存储库有关。我已经阅读了一些有关使用 ssh 的内容,但也看到了不要使用 ssh。

任何建议或帮助将不胜感激!


你能否尝试在https URL中指定用户:https://user@github.com/username/repo.git - VonC
我尝试过那样做,但是得到了相同的错误,只是密码无法读取。 - user2147143
3个回答

19

所以,我解决了这个问题。为了使用 Github 上的私有存储库进行 HTTPS 部署,您需要使用 Github 的 OAuth API。在 Github 帐户的 "编辑个人资料" 下,点击应用程序,然后生成一个 OAuth 令牌。然后,将您的令牌添加到您的存储库 URL 前缀中,如下所示:

 set :repository,  "https://<OAuthToken>@github.com/username/application.git"

之后,我能够跑步了。

 cap deploy

并将我的应用程序部署到远程服务器。


2
在服务器上将OAuthToken存储在文件中,这是一种安全的方法吗?谢谢! - daveomcd

18

错误信息是一个通用的git错误,但问题本身是针对Ruby的。

因此,对于其他人来说,这里有一个非rails的答案:缺失的设备实际上是一个控制台。

  1. 你已经尝试了无交互认证(即使用SSH密钥)。但是失败了。
  2. 作为后备,git尝试提示用户输入用户名,但由于没有可用的交互式控制台而无法工作。

修复方案#1,因为您可能不想在部署期间进行交互式身份验证。在我的情况下,这是一个github oauth问题。


0

致命错误:无法读取'https://github.com'的用户名:没有这样的设备或地址"

首先检查github用户名。另外,您的scm用户是否与代码中的服务器用户相同?

您的代码

 set :scm_user, "user"
 set :user, "user"

应该是这样的

 set :user, "deployer"  # The server's user for deploys
 set :scm_user, "ram"  # The   github username

同时设置密码短语

  set :scm_passphrase, "p@ssw0rd"  # The deploy user's password

现在是关于代码库的问题。我认为你的代码库设置应该是这样的。

set :repository, "git@github.com:username/repo.git"  # Your clone URL

同样也

 set :ssh_options, { :forward_agent => true }

谢谢您的回复!我尝试了所有这些方法,但都没有奏效。正如您上面澄清的那样,我没有正确设置用户名,但更改存储库导致capistrano找不到存储库并显示“Permission denied (publickey). fatal: Could not read from remote repository.”错误信息。 - user2147143

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接