GVKun编程网logo

如何让 git 默认为 ssh 而不是 https 对于新的存储库(git 设置 ssh)

20

想了解如何让git默认为ssh而不是https对于新的存储库的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于git设置ssh的相关问题,此外,我们还将为您介绍关于Facebook在登录后使用

想了解如何让 git 默认为 ssh 而不是 https 对于新的存储库的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于git 设置 ssh的相关问题,此外,我们还将为您介绍关于Facebook 在登录后使用 http 而不是 https 进行重定向、git clone Https 还是 SSH ?、git push to nginx + git-http-backend:error:无法访问URL http返回码22致命:git-http-push失败、git push to nginx git-http-backend:error:无法访问URL http返回码22致命:git-http-push failed的新知识。

本文目录一览:

如何让 git 默认为 ssh 而不是 https 对于新的存储库(git 设置 ssh)

如何让 git 默认为 ssh 而不是 https 对于新的存储库(git 设置 ssh)

这些天,当我在 GitHub 上的设置页面上创建一个新存储库时,我得到:

git remote add origin https://github.com/nikhilbhardwaj/abc.gitgit push -u origin master

每当我必须推送一个提交时,我都需要输入我的 GitHub 用户名和密码。

我可以手动将其更改为

git@github.com:nikhilbhardwaj/abc.git

.git/config. 我觉得这很烦人 -有什么方法可以将 git 配置为默认使用 SSH?

答案1

小编典典

将存储库的源分支设置为 SSH

GitHub 存储库设置页面只是一个建议的命令列表(GitHub 现在建议使用 HTTPS 协议)。除非您对 GitHub 的站点具有管理权限,否则我不知道有什么方法可以更改他们建议的命令。

如果您更愿意使用 SSH 协议,只需像这样添加一个远程分支(即使用此命令代替GitHub 建议的命令)。要修改现有分支,请参阅下一节。

$ git remote add origin git@github.com:nikhilbhardwaj/abc.git

修改预先存在的存储库

如您所知,要将预先存在的存储库切换为使用 SSH 而不是 HTTPS,您可以更改.git/config文件中的远程 URL。

[remote "origin"]    fetch = +refs/heads/*:refs/remotes/origin/*    -url = https://github.com/nikhilbhardwaj/abc.git    +url = git@github.com:nikhilbhardwaj/abc.git

一个快捷方式是使用以下set-url命令:

$ git remote set-url origin git@github.com:nikhilbhardwaj/abc.git

Facebook 在登录后使用 http 而不是 https 进行重定向

Facebook 在登录后使用 http 而不是 https 进行重定向

如何解决Facebook 在登录后使用 http 而不是 https 进行重定向?

我编写了一个 Spring 应用程序和一个 React 行为,以便用户可以使用 Facebook 登录。我还购买了一个带有 SSL 证书的域,并将该证书安装在我的 Nginx 反向代理中。

这是我的 Nginx 配置(它在 docker 容器中运行):

events {
    worker_connections 1024;
}



http {

    server { 
        listen          80;
        server_name     frontend;
        
        location / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP         $remote_addr;
            proxy_set_header x-frame-options   SAMEORIGIN;
            
            proxy_pass http://host.docker.internal:3000/;
        }
    
    }
    
    server { 
        listen                  443 ssl;
        server_name             frontend_secure;
        ssl_certificate         /etc/ssl/private/8e3a263352b3f661.pem;
        ssl_certificate_key     /etc/ssl/private/key.key;
        
        location / {
            proxy_set_header    Host                $http_host;
            proxy_set_header    X-Forwarded-Proto   $scheme;
            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
            proxy_set_header    X-Real-IP           $remote_addr;
            proxy_set_header    x-frame-options     SAMEORIGIN;
            
            proxy_pass          http://host.docker.internal:3000;
        }
        
        location /api {
            proxy_set_header    Host                $http_host;
            proxy_set_header    X-Forwarded-Proto   $scheme;
            proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
            proxy_set_header    X-Real-IP           $remote_addr;
            proxy_set_header    x-frame-options     SAMEORIGIN;
            
            proxy_pass          http://host.docker.internal:8081;
        }
    
    }
}

我将我的 https 域添加到 Facebook 控制台中的应用程序域、站点 URL、域和有效的 OAuth 重定向 URI。在后端 spring 配置中,我将 https 域设置为登录成功 url:

 http.authorizeRequests()
                .antMatchers("/api/users/login**","/callback/","/webjars/**","/error**","/api/users/availableAuths").permitAll()
                .antMatchers("/oauth_login","/loginFailure","/").permitAll()
                .anyRequest().authenticated()
                .and()
                .oauth2Login()
                .defaultSuccessUrl("https://domain.dev/",true)
                .failureUrl("/loginFailure")
                .loginPage("/api/users/availableAuths")
                .and()
                .logout()
        .logoutUrl("/");

我可以正确地看到前端(使用安全 https)并且它正确地重定向到 Facebook 以登录。问题是,当我登录时,我收到此消息:

Facebook has detected Eat App isn''t using a secure connection to transfer information.
Until Eat App updates its security settings,you won''t be able to use Facebook to log into it.

我可以在facebook停止的链接中看到

https://www.facebook.com/v2.8/dialog/oauth? (...) redirect_uri=http%3A%2F%2Fdomain.dev%2Fapi%2Flogin%2Foauth2%2Fcode%2Ffacebook

所以 facebook url 中的 redirect_uri 是 HTTP 而不是 HTTPS。这是为什么?这个带有 http 的 redirect_uri 参数来自哪里?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

git clone Https 还是 SSH ?

git clone Https 还是 SSH ?

Https 和 SSH 的区别

就 Git 而言,https 和 ssh 的区别简单的说就是:

  • https: git clonegit pull 无限制,git push 需要提供 credential,一般是你的 github(如果 remote repository 托管在 github 上的话)的用户名和密码;
  • ssh:因为需要在托管平台上设置 ssh public key,所以要求你必须是该 repository 的拥有者或者管理员。git push 时,无需输入用户名,如果在生成 ssh key 的时候设置了密码,则需要输入密码,否则不需要。

选择过程中的一些建议

  • 如果开发环境在 windows ,产品环境在 linux,建议在 windows 下使用 https,在 linux 下使用 ssh。除了 ssh 本身的限制,这个建议还考虑到其他两个因素:方便、安全。如果 linux 下使用 https,安全性没问题,但为了方便,当然希望在访问 remote repository 时可以免密码。关于这一点,网上大多数的解决方案是将用户名和密码包含在远程地址中,然后使用 git config --global credential.helper store 将 credential 信息以明文方式存储在 .git-credentials 文件中。这样一来,安全性不能保证。所以建议在 linux 下使用 ssh 方式。虽然 ssh key 的部署略微有点麻烦,但是一旦部署好,能同时保证安全性和便捷性。
    因为 linux 下使用了 ssh 方式,并且产品环境下的 ssh private key 不能轻易泄露。所以 windows 下建议使用 https 方式。windows 下有 git-credential-winstoregit-credential-manager-for-windows 用以存储 credential,所以安全性和便捷性同样可以保证。
  • 如果有多人共同维护产品,ssh 无疑是最好的选择。因为多人维护,所以项目部署至产品环境,无论产品环境是 windows 还是 linux,需要一个统一的密码(即使这个密码为空)。如果使用 https 方式,必须以一个人的账号和密码作为 credential, 这样会有两个问题,一是不利于个人隐私的保护,二是如果此人出现人事变动,会带来不必要的麻烦。

 

git push to nginx + git-http-backend:error:无法访问URL http返回码22致命:git-http-push失败

git push to nginx + git-http-backend:error:无法访问URL http返回码22致命:git-http-push失败

我在Ubuntu 14.04(使用Nginx / 1.4.6 + git -http-backend + fastcgi:fcgiwrap 1.1.0-2)configuration我的git repos来通过http服务。 但遇到以下错误。

# git push origin master Username for 'http://server.com': git Password for 'http://git@gittest.cloudthis.com': error: Cannot access URL http://server.com/rahul.git/,return code 22 fatal: git-http-push Failed

我的Nginx网站的configuration如下。

server { listen 80; server_name server.com; root /var/www/git/repos; include /etc/Nginx/fcgiwrap.conf; # Added as a support for cgi auth_basic "Welcome to my GIT repos"; # Added for Basic Auth +1 auth_basic_user_file /etc/apache2/.htpasswd; location ~ /git(/.*) { # location /repos/ { #client_max_body_size 0; include /etc/Nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; fastcgi_param GIT_HTTP_EXPORT_ALL true; fastcgi_param GIT_PROJECT_ROOT /var/www/git/repos; fastcgi_param PATH_INFO $uri; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param REMOTE_USER $remote_user; fastcgi_pass unix:/var/run/fcgiwrap.socket; } }

我的回购根目录为/var/www/git/repos 。 其中我已经初始化我的裸仓库,如/var/www/git/repos/firstrepo.git/使用命令git --bare init firstrepo.git

Git克隆工作正常,但是当我做出改变,并做git push origin master它给出了错误

Nginx / PHP下载而不是执行

Apache或Nginx来服务Django应用程序?

Nginx + fastcgimultithreading

在Nginx中使用FastCGI封装器执行Perl时,我确实获得了速度优势吗?

mod_fcgid:multithreadingFastCGI现在还是在计划的将来?

# touch newfile # git add newfile # git commit -m " commited " [master 059714a] commited 1 file changed,0 insertions(+),0 deletions(-) create mode 100644 newfile # git push origin master Username for 'http://server.com': git Password for 'http://git@server.com': error: Cannot access URL http://server.com/rahul.git/,return code 22 fatal: git-http-push Failed

任何人有任何想法我做错了什么。 也尝试编辑.git / config文件,如上所述

,但没有帮助。 错误保持不变

在我的access.log

114.143.99.83 - - [14/Aug/2014:15:49:33 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 401 203 "-" "git/1.9.1" 114.143.99.83 - - [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 401 203 "-" "git/1.9.1" 114.143.99.83 - git [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 200 59 "-" "git/1.9.1" 114.143.99.83 - git [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/HEAD HTTP/1.1" 200 23 "-" "git/1.9.1" 114.143.99.83 - - [14/Aug/2014:15:49:37 +0000] "PROPFIND /rahul.git/ HTTP/1.1" 401 203 "-" "git/1.9.1"

在我的error.log

2014/08/14 15:49:33 [error] 2872#0: *19 no user/password was provided for basic authentication,client: 114.143.99.83,server: server.com,request: "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1",host: "server.com" 2014/08/14 15:49:36 [error] 2872#0: *20 no user/password was provided for basic authentication,host: "server.com" 2014/08/14 15:49:37 [error] 2872#0: *21 no user/password was provided for basic authentication,request: "PROPFIND /rahul.git/ HTTP/1.1",host: "server.com"

Nginx错误readv()和recv()失败

Magento的Nginx + PHP-FPM + FastCGIcachingconfiguration

在使用django + Nginx + flup时,打印语句写到哪里?

在Apache中调用PHP-FPM中设置正确的REMOTE_ADDR

Nginx的网关超时后60秒

如receivepack 所述,您可以通过启用receivepack选项来解决身份验证问题,但会禁用身份验证的要求 。 你想要的是与git-http-backend进行通信,哪个用户被成功认证。 这可以通过将REMOTE_USER FastCGI参数设置为$ remote_user Nginx变量来完成 。

server { ... location ... { auth_basic "Restricted"; auth_basic_user_file /path/to/.htpasswd; fastcgi_param REMOTE_USER $remote_user; ... } }

考虑到你当前的Nginx配置,你可能会遇到一个问题,那就是与fcgiwrap的连接过早关闭,这与FastCGI参数的顺序有关系 。 如果/etc/Nginx/fastcgi_params包含SCRIPT_FILENAME的定义,那么在使用fcgiwrap时,它不会被/usr/lib/git-core/git-http-backend覆盖。

我有类似的设置,你有。

我认为问题是关联的接收包选项。

您应该将此选项添加到裸仓库的配置文件中

[http] receivepack = true

或者对于系统范围的设置(如我所做的那样),在/ etc / gitconfig中插入上面的行

您也可以像这样使用config命令来启用存储库:

git config –local http.receivepack true

或者全系统地做:

git config –system http.receivepack true

与Nginx相关的,你也可以在一个位置块中使用身份验证,而不是服务器,这使得配置更加干净(IMO)。

git push to nginx git-http-backend:error:无法访问URL http返回码22致命:git-http-push failed

git push to nginx git-http-backend:error:无法访问URL http返回码22致命:git-http-push failed

我正在配置我的git repos以在Ubuntu 14.04中使用http服务(使用Nginx / 1.4.6 git-http-backend fastcgi:fcgiwrap 1.1.0-2).但抓住了以下错误.

# git push origin master
Username for 'http://server.com': git
Password for 'http://git@gittest.cloudthis.com': 
error: Cannot access URL http://server.com/rahul.git/, return code 22
fatal: git-http-push Failed

我的Nginx网站的配置如下.

server {

    listen          80;
    server_name     server.com;
    root            /var/www/git/repos;

include /etc/Nginx/fcgiwrap.conf; # Added as a support for cgi

auth_basic          "Welcome to my GIT repos";  # Added for Basic Auth +1
auth_basic_user_file    /etc/apache2/.htpasswd;

    location ~ /git(/.*) {
#    location /repos/ {

#client_max_body_size                   0;
        include /etc/Nginx/fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
        fastcgi_param   GIT_HTTP_EXPORT_ALL     true;
        fastcgi_param   GIT_PROJECT_ROOT        /var/www/git/repos;
        fastcgi_param   PATH_INFO               $uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param   REMOTE_USER             $remote_user;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }
}

我有我的repos根目录为/ var / www / git / repos.我使用命令git –bare init firstrepo.git初始化了我的裸存储库,如/var/www/git/repos/firstrepo.git/

Git克隆工作正常,但是当我进行更改并执行git push origin master时,它会给出错误

# touch newfile
# git add newfile
# git commit -m " commited "
[master 059714a]  commited
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 newfile
# git push origin master
Username for 'http://server.com': git
Password for 'http://git@server.com': 
error: Cannot access URL http://server.com/rahul.git/, return code 22
fatal: git-http-push Failed

任何人都知道我做错了什么.还尝试编辑.git / config文件,如here所述

,但它没有帮助.错误保持不变

在我的access.log中

114.143.99.83 - - [14/Aug/2014:15:49:33 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 401 203 "-" "git/1.9.1"
114.143.99.83 - - [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 401 203 "-" "git/1.9.1"
114.143.99.83 - git [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1" 200 59 "-" "git/1.9.1"
114.143.99.83 - git [14/Aug/2014:15:49:36 +0000] "GET /rahul.git/HEAD HTTP/1.1" 200 23 "-" "git/1.9.1"
114.143.99.83 - - [14/Aug/2014:15:49:37 +0000] "PROPFIND /rahul.git/ HTTP/1.1" 401 203 "-" "git/1.9.1"

在我的error.log中

2014/08/14 15:49:33 [error] 2872#0: *19 no user/password was provided for basic authentication, client: 114.143.99.83, server: server.com, request: "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1", host: "server.com"
2014/08/14 15:49:36 [error] 2872#0: *20 no user/password was provided for basic authentication, client: 114.143.99.83, server: server.com, request: "GET /rahul.git/info/refs?service=git-receive-pack HTTP/1.1", host: "server.com"
2014/08/14 15:49:37 [error] 2872#0: *21 no user/password was provided for basic authentication, client: 114.143.99.83, server: server.com, request: "PROPFIND /rahul.git/ HTTP/1.1", host: "server.com"

解决方法:

作为described by Marcs,您可以通过启用receivepack选项解决您的身份验证问题,但是这个disables the requirement for authentication.您更希望的是与git-http-backend进行通信,哪个用户已成功通过身份验证.这可以通过将REMOTE_USER FastCGI参数设置为$remote_user Nginx variable来完成.

server {
    ...
    location ... {
        auth_basic "Restricted";
        auth_basic_user_file /path/to/.htpasswd;
        fastcgi_param REMOTE_USER $remote_user;
        ...
    }
}

考虑到您当前的Nginx配置,您可能还会遇到与fcgiwrap的连接过早关闭的问题,这与order of FastCGI parameters matter有关.如果/ etc / Nginx / fastcgi_params包含例如: SCRIPT_FILENAME,使用fcgiwrap时不会被/usr/lib / git-core / git-http-backend覆盖.

我们今天的关于如何让 git 默认为 ssh 而不是 https 对于新的存储库git 设置 ssh的分享已经告一段落,感谢您的关注,如果您想了解更多关于Facebook 在登录后使用 http 而不是 https 进行重定向、git clone Https 还是 SSH ?、git push to nginx + git-http-backend:error:无法访问URL http返回码22致命:git-http-push失败、git push to nginx git-http-backend:error:无法访问URL http返回码22致命:git-http-push failed的相关信息,请在本站查询。

本文标签: