In this article we are going to connect two PCs connected to the same router i.e. we’ll open folder on one PC as virtual folder on the other one with the help of SSHFS. As for me I’ve connected PC Ubuntu 16.04 with notebook Ubuntu 14.04.
From Networking Ubuntu PC’s With SSHFS:
SSHFS uses OpenSSH to provide secure (encrypted) communications between PCs. With the network connected, the local PC user will be able to transfer, open, and edit files on the remote PC, as if they were on his own PC. The remote files will look and act just like the files on the local PC.
Ubuntu comes with most of the software to make this work, but needs two applications, available in the repositories, to be installed on both PCs.
$ sudo apt-get install sshfs $ sudo apt-get install openssh-server
openssh-client is usually pre installed
$ sudo apt-get install openssh-client
From How to mount a remote ssh filesystem using sshfs:
Now, let us create a local directory where you want the files mounted. You should create the directory and make yourself the owner of the directory:
$sudo mkdir /media/dir-name $sudo chown your-username /media/dir-name
Go to System->Administration->Users and Groups, select the group “fuse” and then add yourself to this group. If you prefer to do it th easy way, on the command line, then use
$sudo adduser your-username fuse
Then
$sshfs remote-username@192.168.1.33:/home/remote-username /media/dir-name remote-username@192.168.1.33's password:
Where ‘remote-username’ is user name on the remote PC and ‘password’ is password on the remote PC. Here 192.168.1.33 is IP taken as an example. You can get it from wi-fi connection data. /home/remote-username – is folder on the remote PC which you are going to open on the local one.
More detailed description you can find via two links which I have provided.
So as a result we have to fulfill this action
$sshfs remote-username@192.168.1.33:/home/remote-username /media/dir-name remote-username@192.168.1.33's password:
every time we are going to connect to an other PC. Surely it’ll be tiresome.
So let’s create batch file in /home/your–username folder and name it pc_connect.sh.
#!/bin/bash echo 'password' | sshfs -o password_stdin remote-username@192.168.1.33:/home/remote-username /media/dir-name
In the first line of batch file we have shebang :
… shebang is the character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script.
Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script’s initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script.
To sshfs command we added option ‘-o password_stdin’ . Here is help description ($ sshfs -h):
-o password_stdin read password from stdin (only for pam_mount!)
This gives us the ability to write password in batch file and not to input it manually. Now we can execute this batch file via console
$cd $./pc_connect.sh
If we want to run batch file via double click we have to do some more actions :
-make .sh file executable
$sudo chmod +x ./pc_connect.sh
-in Ubuntu Files window select in menu Edit->Preferences ->Behavior tab and select both “Double click to open items” and “Run executable text files when they are opened”.