How to forward local keypair in a SSH session?

后端 未结 3 926
南笙
南笙 2020-12-23 13:24

I manually deploy websites through SSH, I manage source code in github/bitbucket. For every new site I\'m currently generating a new keypair on the server and adding it to g

相关标签:
3条回答
  • 2020-12-23 14:06

    This turned out to be very simple, complete guide is here Using SSH Forwarding

    In essence, you need to create a ~/.ssh/config file, if it doesn't exist.

    Then, add the hosts (either domain name or IP address in the file and set ForwardAgent yes)

    Sample Code:

    Host example.com
        ForwardAgent yes
    

    Makes SSH life a lot easier.

    0 讨论(0)
  • 2020-12-23 14:20

    The configuration file is very helpful but the trick for agent forwarding does the ssh-add command. It seems that this have to be initial triggered before any remote connections or after restart of the computer. To permanently add the key try the following solution from the user daminetreg: Add private key permanently with ssh-add on Ubuntu

    0 讨论(0)
  • 2020-12-23 14:23
    1. Create ~/.ssh/config
    2. Fill it with (host address is the address of the host you want to allow creds to be forwarded to):

      Host [host address]
           ForwardAgent yes
      
    3. If you haven't already run ssh-agent, run it:

      ssh-agent
      
    4. Take the output from that command and paste it into the terminal. This will set the environment variables that need to be set for agent forwarding to work. Optionally, you can replace this and step 3 with:

      eval "$(ssh-agent)"
      
    5. Add the key you want forwarded to the ssh agent:

      ssh-add [path to key if there is one]/[key_name].pem
      
    6. Log into the remote host:

      ssh -A [user]@[hostname]
      
    7. From here, if you log into another host that accepts that key, it will just work:

      ssh [user]@[hostname]
      
    0 讨论(0)
提交回复
热议问题