ssh keygen ssh add

ssh kegen

Posted by Yuan on August 30, 2021

ssh-keygen

ssh-keygen pairs:

  1. Generate key pairs The algorithm is selected using the -t option and key size using the -b option. The following commands illustrate:
    1
    2
    3
    4
    5
    6
    
    ssh-keygen -t rsa -b 4096 
    ssh-keygen -t dsa 
    ssh-keygen -t ecdsa -b 521 
    ssh-keygen -t ed25519
    ssh-keygen -t ed25519 -C "your_email@example.com"
    ssh-keygen -f ~/tatu-key-ecdsa -t ecdsa -b 521
    
  2. Copy the pubkey to the server user@host: the username and address of the remote machine

    ssh raymond@192.168.1.50

For github, copy pubkey using pdcopy and paste to SSH keys settings using web.

1
ssh-copy-id -i ~/.ssh/tatu-key-ecdsa.pub user@host

If ssh-copy-id not installed, takes your public key, and appends it to ~/.ssh/authorized_keys

1
cat ~/.ssh/tatu-key-ecdsa.pub | ssh user@host "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

copy pub key

1
pdcopy < ~/.ssh/tatu-key-ecdsa.pub

Once the public key has been configured on the server, the server will allow any connecting user that has the private key to log in.

  1. Add private key to ssh agent

    Firstly, run ssh-agent:

    1
    
     eval `ssh-agent`
    

    Then, add private key:(You may need to change privatekey into a 400 access code)

    1
    
     ssh-add ~/.ssh/privatekey
    

    Finally, Test:

    1
    
     ssh -vT git@github.com