If you using UBUNTU or OTHER LINUX OS be aware of the silent killer
"rm -rf" - it removes everything without a warning. Once removed recovery may not be possible or extremely hard.
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.
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.
Transfer files one machine to another 1
These days I transfer files one machine to another frequently. There are few ways to do that.
1. scp (ssh)
2. using apache server
3. sshfs (by mounting remote directory)
4. the most easy two ways (this can be used even you don't know the ip address)
In this post I covered first two and will cover the next two in the 2nd part.
SCP (SSH)
To do this you need to install ssh-client in your machine and ssh-server in the other machine.
If you use Ubuntu in your machine you can install this by using sudo apt-get install openssh-client or openssh-server or you can download it and install from here.
If you have install ssh-client and server in your both machines then you can copy files from each another. To do this you can use the following command.
copy a file from remote machine to your machine
=>scp user@remote.host:file-path path-to-save
eg: copy a remote file named remotefile.txt which located in Desktop of the remote machine to your Desktop
scp eranda@10.0.0.4:Desktop/remotefile.txt ./Desktop
copy a file from your machine to remote machine
=>scp file-path user@remote.host:path-to-save
eg:copy a file named remotefile.txt which located in Desktop of your machine to the Desktop of a remote machine
scp ./Desktop/myfile.txt eranda@10.0.0.4:/home/eranda/Desktop
Using apache server
For this you have to have apache server install in your machine. If you do not have you can install using the command sudo apt-get install apache2 or you can download and install the apache server from here.
After installing apache2 your server should be up and running.
You can see that by going to the URL http://localhost/
You can see this kind of message in it.
------------------------------------------------------------------------------
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet
-----------------------------------------------------------------------------
If you see a Server Not Found 404 message, then you should start the apache2 server. You can do that by as follows
change directory to /usr/local/apache2
and execute the following commands
./clean.sh
./start.sh
Now lets start the file transferring.
First make directory in the location /var/
Put the file you want to copy to remote machine in that folder
For example I created a directory eranda in /var/ and put two of my files in that.
Now go to the remote machine and open a browser
Go to the URL http://your_machine_/your_folder_name (eg: http://10.0.0.4/eranda/)
You can see the files you put in the folder in your machine as follows
Now what you have to do is double click on the file you need and it will start downloading.
Special thank goes to Damitha Kumarage, Tech lead at WSO2 Inc.
Subscribe to:
Posts (Atom)