# Accessing data on local machine from remote kernel

I have a remote kernel on a server that I would like to use to process some data. The connection works, i.e, I'm able to use the local front end and the remote kernel. However, I cannot figure out how should I access from the remote kernel the data that are on my local machine.

I thought I could simply use Import with the path to my computer and to the file that I want to import, but I didn't succeed. Something like:

Import["computerName@ip_address:/Users/myUserName/Desktop/data.txt","Table"]


-
Import the data in the frontend and do DistributeDefinitions? –  Ajasja Jan 18 at 16:33
@Ajasja I looked at the documentation for DistributeDefinitions, but I don't get it how I should use it. For instance, f[n_] := PrimeQ[2^n - 1] and then DistributeDefinitions[f]; should transport the definition to all kernels. But when I try f[2] from the FE connected to the remote kernel the output is f[2] instead of True. –  VLC Jan 18 at 17:13
Ahh, sorry I thought they were slave kernels (for parallel computations), but you have the FE connected directly to a remote kernel. Then you have to share a disk or a drive or copy your data on some webserver... –  Ajasja Jan 18 at 17:17

After some fiddling I found a solution to directly access my local files from the remote kernel via SSH. If localuser is the user name on the machine that runs the front end on which are also the data you want to import from the remote kernel and 111.111.111.11 is the IP address of the same machine, you just need to type:

Import["!ssh localuser@111.111.111.11 cat /Users/localuser/Desktop/data.txt", "Table"]


To make this work smoothly you first need to set up public key authentication over SSH. Let remoteuser be the user name on the machine that runs the remote kernel and let 222.222.222.22 be the IP address of the remote machine.

On your local machine launch the terminal:

1. Generate a public key:
• ssh-keygen -t rsa
2. Ok, when asks to save it in:
• .ssh/id_rsa
3. Press return when asks for passphrase.
4. Press return againg when asks for passphrase.
5. Copy the public key on the remote machine:
• scp id_rsa.pub remoteuser@222.222.222.22:/home/remoteuser
6. Connect to remote machine:
• ssh remoteuser@222.222.222.22
7. Append the public key (previously copied from local machine to remote machine) to the list of authorized keys:
• cat id_rsa.pub >> .ssh/authorized_keys
8. Generate a public key on the remote machine:
• ssh-keygen -t rsa
9. Ok, when asks to save it in: -.ssh/id_rsa
10. Press return when asks for passphrase.
11. Press return againg when asks for passphrase.
12. Copy the public key on the local machine:
• scp id_rsa.pub localuser@111.111.111.11:/Users/localuser
13. Exit from remote server: CTRL+D
14. Append the public key (previously copied from remote machine into local home) to the list of authorized keys:
• cat id_rsa.pub >> .ssh/authorized_keys
-
Nice hack :) +1 –  sebhofer Jan 21 at 14:19
Is there a similar solution for the Export? –  ybeltukov Sep 9 at 23:16
@ybeltukov I don't know if it works, but did you try to follow all the steps above and then simply Export["!ssh localuser@111.111.111.11 cat /Users/localuser/Desktop/newfile.txt", data, "TSV"], where data is the dataset you want to export? –  VLC Sep 16 at 12:13