Wednesday, July 21, 2010

Transfer files one machine to another 2

I blog about two methods in the first and here is the second part which describes about
1. sshfs method
2. secret most easy two ways

SSHFS(mounting remote directory)

Here I am going to describe how to copy a file to remote machine using mounting it on to your machine. Lets see how to do that,
First you need sshfs install in your machine. You can do that by executing following command
sudo apt-get install sshfs.
Then what you have to do is create a folder in your machine where you want to mount the directory.
For example lets create a directory named eranda in Desktop.
Now you have to change the own of that folder, and it's content.
To do that execute the following command
chown -r username.username directory
eg: chown -r eranda.eranda Desktop/eranda

Now ready to mount the image.
You can mount the directory using the following command.
sshfs -o idmap=user username@remote-host:remote-directory your_directory
eg:sshfs -o idmap=user ishan@10.0.0.2:Desktop/xxx /home/eranda/Desktop/eranda

Now you can see the whole content of the xxx directory of the remote machine in your mounted folder. Now you can do r, w, x, copy from, copy to, delete, anything using that directory as a your local directory.
WARNING: All the changes that you done to this is changes to the original directory

As our main target now you can copy to/from remote machine.

After doing what you want you can unmount the directory as follows.
fusermount -u /home/eranda/Desktop/eranda

Two easy ways

1. Use a flash/portable drive etc...
2. Use a CD/DVD/Blue Ray etc...

NOTE: When you connect to the remote machine using ssh, scp or sshfs you always need to type the password of that user. If you doing it frequently you can save a passkey to that machine which will allow you to access without password. Now lets see how can we do that.

First you need to create a key.
ssh-keygen -t rsa
Now save it in the remote machine. To do that you first you should change your current location to home. Then execute the following command.
cat .ssh/id_rsa.pub | ssh user@remote.host 'cat >>.ssh/authorized_keys'


Special thanks to Damitha Kumarage, Tech lead at WSO2 Inc.

No comments:

Post a Comment