Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaysridhar/cd7fc7ae98e8bc0bcf13dd3bb02e1be6 to your computer and use it in GitHub Desktop.
Save jaysridhar/cd7fc7ae98e8bc0bcf13dd3bb02e1be6 to your computer and use it in GitHub Desktop.

If you dont have a keypair, Create the RSA Key Pair using ssh-keygen tool

The first step is to create the key pair on the client machine (there is a good chance that this will just be your computer):

ssh-keygen -t rsa -b 4096 -C "[email protected]"

This creates a new ssh key, using the provided email as a label. The entire key generation process looks like this:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/demo/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/demo/.ssh/id_rsa.
Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
The key fingerprint is:
4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a
The key's randomart image is:
+--[ RSA 2048]----+
|          .oo.   |
|         .  o.E  |
|        + .  o   |
|     . = = .     |
|      = S = .    |
|     o + = +     |
|      . o + o .  |
|           . o   |
|                 |
+-----------------+

The public key is now located in /home/demo/.ssh/id_rsa.pub. The private key (identification) is now located in /home/demo/.ssh/id_rsa.

Copy the SSH Public key

After the key pair is generated, it’s time to place the public key on the server that we want to use. You can copy the public key into the new machine’s authorized_keys file with the ssh-copy-id command. Make sure to replace the example username and IP address below.

ssh-copy-id [email protected]

Note: If you are a Mac user, ssh-copy-id will not be installed on your machine. You can, however, install it using Homebrew:

brew install ssh-copy-id

Alternatively, you can paste in the keys using SSH:

cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >>  ~/.ssh/authorized_keys"

If you have generated the Keys in the same server machine, run

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Setting up Windows Machine

  1. copy the ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub to your windows User folder %userprofile%/.ssh
  2. Follow the SSHwin-fs guideline to install sshwin-fs in your windows machine
  3. Run the following command to mount the linux machine as a drive
"C:\Program Files\SSHFS-Win\bin\sshfs-win.exe" svc \sshfs.k\<username>@<host>\.. X:
  1. Access the linux files from X: directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment