Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthikmurugesan2/f924f6b7a308094efaacfe5ee6f82f2b to your computer and use it in GitHub Desktop.
Save karthikmurugesan2/f924f6b7a308094efaacfe5ee6f82f2b 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 "your_email@example.com"

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 demo@198.51.100.0

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 demo@198.51.100.0 "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.
@asdffdsazqqq
Copy link

hello, thanks.

can you please help explain how to specify a id_rsa file that is in custom location, NOT stored in %userprofile%/.ssh
fwiw, i do this easily with windows terminal.

i have tried a million varatitions, such trying to change the slash, use double slash, use linux path style but this never works.

"C:\Program Files\SSHFS-Win\bin\sshfs-win.exe" svc \sshfs\root@xxx.89.105.48 X: -o -i "C:\data\c\combined\hetzner\03\keys\keys.priv" 

sshfs: invalid argument `C:\data\c\combined\hetzner\03\keys\keys.priv'

thanks much,
david

@dancintree
Copy link

Hi
Late but I guess -i might not like , try
-o IdentityFile=/path/to/key

@2tefan
Copy link

2tefan commented May 28, 2023

To use another key name use this:
"C:\Program Files\SSHFS-Win\bin\sshfs-win.exe" svc \sshfs.k\<username>@<host>\.. X: "IdentityFile=~\.ssh\key_name"

So in your case @asdffdsazqqq it's:
"C:\Program Files\SSHFS-Win\bin\sshfs-win.exe" svc \sshfs.k\root@xxx.89.105.48 X: "IdentityFile=C:\data\c\combined\hetzner\03\keys\keys.priv"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment