Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount a folder on amazon ec2 instance with private key using sshfs

I am trying to mount a folder on my amazon ec2 instance to my desktop folder using sshfs.

The problem is that I am not able to figure out how to give the option for private key (awskey.pem).

Normally I ssh using

ssh ec2-user@{amz-ip-address} -i {path to amzkey.pem}

But sshfs has no such options. However I saw a -F option and tried

sshfs ec2-user@{amz-ip-address}:{amz-folder}  {my mount dir} -F {path to amzkey.pem}

This gave me an error

"read: Connection reset by peer"

Please let me know if anyone has tried this before.

like image 585
Sanath Ballal Avatar asked Mar 06 '14 07:03

Sanath Ballal


People also ask

How do you attach a key pair to an instance?

To add or replace a key pairConnect to your instance using your existing private key. Using a text editor of your choice, open the . ssh/authorized_keys file on the instance. Paste the public key information from your new key pair underneath the existing public key information.

How do I move a folder from local machine to EC2 instance?

Open a new command prompt and run the following command replacing the fields as needed: scp -P 2222 Source-File-Path user-fqdn @localhost: To copy the entire directory instead of a file, use scp -r before the path. This recursively copies all of the directory's contents to the destination EC2 instance.

How do I create a shared folder between two EC2 instances?

You can simply create a security group and then add an inbound rule to allow all traffic from it's own security group and then add these security group in both instances to share data with each other but there's an better approach for this is to use FSx in AWS.


2 Answers

From the documentation:

If you are using non-default key names and are passing it as -i .ssh/my_key, this won't work. You have to use -o IdentityFile=/home/user/.ssh/my_key, with the full path to the key.

like image 129
Uri Agassi Avatar answered Oct 20 '22 21:10

Uri Agassi


Here is the command for anyone trying this in future

sudo sshfs {username}@{ipaddress}:{remote folder path}  {local folder path} -o IdentityFile={full path to the private key file} -o allow_other
like image 33
Sanath Ballal Avatar answered Oct 20 '22 20:10

Sanath Ballal