Git clone through a reverse tunnel

后端 未结 5 1426
余生分开走
余生分开走 2021-02-04 03:24

I have my Git repo on my machine, which has no public IP of its own, at home; I want to clone this repo at my web server. Is it correct that a reverse tunnel will allow me to pu

相关标签:
5条回答
  • 2021-02-04 04:07

    You can open the ssh port on your firewall and set routing on your router to hit your machine. You'll only need the ip that your router exposes.

    0 讨论(0)
  • 2021-02-04 04:09

    In principle, you can do something like

    ssh -R 2222:localhost:22  username@webserver.com 
    

    and then use on your webserver

    git clone ssh://user@localhost:2222/path/to/repo.git/
    

    This will encrypt your data twice, though.

    Alternatively, you can use any of the other protocols which git supports, and forward the right ports for these.

    You can also put a section like this into ~/.ssh/config:

    Host my-server
    HostName localhost
    ForwardX11 no
    Port 2222
    

    Then you can use this clone command: git clone git@my-server:mytools/projectName.git. (This allows you to store the server's key not as belonging to localhost, and makes the URL in your git config clearer.)

    For your server (both the tunnel server and the final host) you usually want to authenticate per public-key authorization, for this you should put the private key (e.g. id_rsa) in your ~/.ssh directory. (And all files there, specifically the private key, should be readable only for your user, and the directory writable only for your user.)
    All this is not specific for the tunnel, but generic SSH stuff.

    0 讨论(0)
  • 2021-02-04 04:11

    Another alternative is to set up a bare repository on your server, and push to it from your local machine. Pull from there into your server's repository.

    There are many advantages:

    • you don't have to expose your private machine
    • you can work from multiple machines (e.g. your laptop and your desktop), each of which has a clone of your bare repo
    • you can even make patches on your server, push to the bare repo, and pull them onto your working machine.

    See http://joemaller.com/990/a-web-focused-git-workflow/ for a good description.

    0 讨论(0)
  • 2021-02-04 04:14

    I haven't tried this myself (and can't speak for how well it deals with NAT), but it sounds like DynDNS could be one solution to your problem. It provides a public URL to your home machine that can even update itself automatically. From their support page:

    The free Dynamic DNS service provides an easy-to-remember URL for quick remote access to your network. This allows you to reach services at home, such as a personal website, security camera, VPN, game server, and more, using a simple web address like http://myhome.dyndns.org/, instead of a meaningless, ever-changing IP address like http://123.45.67.89. You can learn more about how Dynamic DNS works here.

    Of course, because this will make it easier for other people to access your computer, as well, you should also take appropriate security measures. If it works, though, you could just ssh into your home machine through the DynDNS URL.

    0 讨论(0)
  • 2021-02-04 04:18

    You could push the changes to the web server, instead of trying to pull them:

    Set up a repos on the web server:

    cd /somedir
    git init --bare
    

    Push to that repos from your dev machine:

    git remote add web user@web:/somedir
    git push web master 
    

    If you want to push to a non-bare repos (e.g. if your web app runs in a checkout), then you will need to push to a branch which is not currently checked out and then merge in.

    i.e. on your dev machine:

    git push web master:master-from-dev
    

    then log into the web machine and do:

    git merge master-from-dev
    
    0 讨论(0)
提交回复
热议问题