Home  >  Article  >  Development Tools  >  How to set up ssh agent on multiple platforms and use it in Git

How to set up ssh agent on multiple platforms and use it in Git

PHPz
PHPzOriginal
2023-04-07 09:01:05998browse

SSH Agent Settings Git

When using Git for version control, we sometimes need to access the Git server through an SSH agent to solve problems in network environments that cannot be directly accessed. This article explains how to set up an SSH agent on Windows, Linux, and macOS systems, and use the agent with Git.

Windows

In Windows systems, we can use PuTTY software to set up the SSH agent. The specific steps are as follows:

  1. Download and install PuTTY software, download address: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html.
  2. Open the PuTTY software, enter the host name and port number of the Git server in the Session panel, and click Open to enter the terminal.
  3. Enter your username and password in the terminal to log in to the Git server.
  4. Select Connection -> SSH -> Tunnels in the left panel of PuTTY software and set the local port and target host port, as shown in the figure:

    How to set up ssh agent on multiple platforms and use it in Git

  5. Click the Add button to save the settings and return to the Session panel.
  6. Save the current settings in the Session panel for quick login next time.
  7. Now we can access the Git server through the local proxy port. In Git Bash or other terminals, use the following command to set the proxy:

    git config --global core.gitproxy "socks5://127.0.0.1:1080"

    where "127.0.0.1:1080" is the local proxy port we set in PuTTY.

Linux and macOS

In Linux and macOS systems, we can use the OpenSSH client to set up the SSH agent. The specific steps are as follows:

  1. Enter the following command in the terminal to open the SSH configuration file:

    vi ~/.ssh/config
  2. Add the following content at the end of the file:

    Host git.example.com
        ProxyCommand nc -w 120 -X connect -x socks5://127.0.0.1:1080 %h %p

    Among them, "git.example.com" is our Git server host name, and "127.0.0.1:1080" is our local proxy address and port.

  3. Now we can test whether the SSH agent is successfully configured by using the following command:

    ssh git.example.com

    If the Git server is successfully connected, it means that the SSH agent has been set up normally.

  4. Finally, use the following command in the terminal to set up the Git proxy:

    git config --global core.gitproxy "command nc -x 127.0.0.1:1080 %h %p"

    Among them, "127.0.0.1:1080" is our local proxy address and port.

Summary

Through the above steps, we can quickly set up an SSH agent to access the Git server in Windows, Linux and macOS systems. In actual project development, setting up agents appropriately can improve our work efficiency and solve problems caused by network environment limitations.

The above is the detailed content of How to set up ssh agent on multiple platforms and use it in Git. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn