Ubuntu: Accessing a remote file via ssh on Ubuntu 12.04 [duplicate]


This question already has an answer here:

I have a text file on one of my computers that is running 12.04. I was planning to use ssh to allow for another computer to read this text file. The issue is that the system that I am working with is basically logging some information on this text file at real time. I need for the computer that is going to read this text file, to read the text file at real time as well.

I am not savvy at all with ssh, but I am familiar with ubuntu. If anyone can provide some insight as to how to do this, or if it is even possible to read this text file at real time while another system is logging info it would be greatly appreciated.

Thank you.


What do you mean by "read" the file? If you just want to echo the contents back to the STDOUT, then this should do it.

ssh user@remoteHostName 'tail -f /myDirectory/myFile.txt'  

That should work if you have SSH set up properly, "user" is a valid user on your remote host, and the -f flag on the tail command will allow it to view a file as it grows.


You can use sshfs. Install and setup sshfs.

After setting up sshfs add this 2 alias to your .bashrc.

alias fuse-mo='sshfs remote_user@remote_server:/home/ternovi/your_local_folder /home/remote_user/folder_with_file -o idmap=user -o reconnect'  alias fuse-um='fusermount -u /home/ternovi/your_local_folder'  

Now create folder /home/ternovi/your_local_folder with desired path.

If you execute alias fuse-mo, fuse module will mount remote folder to your local folder, and you will see remote files on your local machine in /home/ternovi/your_local_folder. You can work with this files as they are local.

Alias fuse-um will unmount remote file system.

You can use tail -f /home/ternovi/your_local_folder/file.txt to see latest output to this file. Or you can use any editor you want.

For example open file in vim:

vim /home/ternovi/your_local_folder/file.txt  

And you can type :e to reload current file.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »