Adding ssh keys

SSH access concept

Add server public key (rsa) to client & client public key to server

Get Server ssh rsa public key

Normally server have default key, so just fetch it (or can generate new keys at server - same as client)

ssh-keyscan server_ip_address
Output (all available keys): //hash # followed are comments
# server_ip_address SSH-2.0-OpenSSH_7.4
server_ip_address ssh-rsa
AAAAB3NzaC1yc2EAAAADo
+TKzCq+qq1+NyaVXXTVM2mgTuB8Xs90PrudpFdlFt
+fdc3FTcKXFIyNY3DnU03YwiuwJzjytNL6bl8qK
Qw9xNwpa0kNqM9osfRq58c/dYePJlGWn/BSPifIotgW5ssdOD8HCZ/
mMCpsTipFJsaYSzp0FJ8lzBj/
nguufZOfHMbMa9nrnAOqqvLXropcxXcquaQj2LMsZ1hB9FldUCne
Rv1W0FNNJLA3eXE2ZiKrnizQLEso0oqf2Nf3T6KaPTLOwRA7Hjadz
++/XpS89jaSwdLBwK/oaMYaqwWxtjF76nUFn1
# server_ip_address SSH-2.0-OpenSSH_7.4
server_ip_address ssh-ed25519 AAAAC3NzaC1lZDER7XhFNTj5KPNAIYkndMnOMm
# server_ip_address SSH-2.0-OpenSSH_7.4
server_ip_address ecdsa-sha2-nistp256 AAAAE2VjZkWi7qg+CTa4BTyWIKJqex9/
xd4OHAXRWIjYofBSffhnE9AsRwIbFLaS5sURk8ibVOrBDqnimsHIS9fijJfY=

(copy the first ssh-rsa key line)

Add Server ssh rsa public key to client

In client machine , go to 'C:\Users\user_name.ssh' folder

  • create/ open 'known_hosts' file (no extension), add following lines to it
server_ip_address ssh-rsa AAAAB3NzaC1yc2EAAA..... (paste the first ssh-rsa key line)

Generate client ssh rsa keys

(bash cmd) Start by generating a new 4096 bits SSH key pair with your email address as a comment:

ssh-keygen -t rsa -b 4096 -C "office_email@domain.com"

(just hit enter for defaults)

Now id_rsa, id_rsa.pub files will be save at 'C:\Users\user_name.ssh' folder

Add client ssh rsa public key to server

//if default key
ssh-copy-id remote_username@server_ip_address
//if custom port & key
ssh-copy-id -p customPort-i ~/.ssh/myPublickey remote_username@server_ip_address

You will be prompted to enter the remote_username password

output:

Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'remote_username@server_ip_address'"
and check to make sure that only the key(s) you wanted were added.

Note : in server, .ssh -> "authorized_keys" file has all keys

Test the key

//if default
ssh remote_username@server_ip_address
//if custom
ssh -p customPort-i ~/.ssh/myPrivatekey remote_username@server_ip_address

Add SSH to tortoise GIT

  • Install putty software
  • Open puttyGen, Load your private ssh key (c/users/.ssh/id_rsa) file & save again - so that you get .ppk file

Putty SSH

  • In TortoiseGit, Open the Contextmenu and Navigate "Settings"
  • In the now opened window Navigate to "Git > Remote "
  • Select "Origin" from remote section & add "putty key" in browse file options

Tortoise git SSH

SSH shortcuts

  • If you are connecting to a machine regularly using SSH, then define config short hand for same link

say normally we connect

ssh john@dev.example.com -p 2222

In ~/.ssh/config file:

Host dev
HostName dev.example.com
User john
Port 2322
IdentityFile /path/to/private/key

Now can connect as following

ssh dev

SSH Errors

ssh unable to negotiate - no matching key exchange method found

//syntax
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c SUPPORTED_CIPHER_NAME END_USER@IPADRESS
Note : SUPPORTED_CIPHER_NAME list will be shwn in error
//example
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -c 3des-cbc myUser@10.10.10.1
  • style 2 (adding those setting in .ssh/config file)
Host 10.10.10.1
Ciphers 3des-cbc
KexAlgorithms +diffie-hellman-group1-sha1
Port 1234