Skip to content

Instantly share code, notes, and snippets.

@stupidbodo
Last active December 22, 2015 18:19
Show Gist options
  • Save stupidbodo/6512066 to your computer and use it in GitHub Desktop.
Save stupidbodo/6512066 to your computer and use it in GitHub Desktop.
Generate ssh keys and connect from windows to linux
#!/bin/bash
# Generate SSH Keys and connect Windows to Linux #
#################
# go to ssh directory
cd ~/.ssh
# Generate ssh key
ssh-keygen -t rsa -C "<<enter some random stuffs as label>>"
# Prompt "Enter file in which to save the key (/c/Users/you/.ssh/id_rsa):"
[Enter your key name. In this case we call it "somekey"]
# Prompt "Enter passphrase (empty for no passphrase):"
[Enter a passphrase]
# See your public ssh key
cat ~/.ssh/somekey.pub
# somekey.pub is your public key
# somekey is your private key. Hide it in your undies
# To connect from windows to your linux server, your linux server MUST HAVE the public key in the file "~/.ssh/authorized_keys"
# Some hosts allows you to add ssh key in server creation process. Alternatively, you can use the command below to
# add the public key.
cat .ssh/somekey.pub | ssh user@123.45.56.78 "cat >> ~/.ssh/authorized_keys"
# Once the linux server have your public key. Go to your .ssh directory and connect remotely.
cd ~/.ssh
ssh -i <<keyname>> user@123.45.56.78
# After which you can disable password for root login
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment