简体   繁体   中英

Connected to ssh session via my browser. How can I access my local files through the browser?

I'm connected to a VM on a private network at address 'abc.def.com' using ssh , and on that VM there's an application that hosts a Python web app (IPython Notebook) that I can access by pointing my local browser to 'abc.def.com:7777'.

From that web app I can call shell commands by preceding them with '!', for example !ls -lt will list the files in the VM current working directory. But since I'm using my own laptop's browser, I think I should be able to run shell commands on my local files as well. How would I do that?

If that's not possible, what Python/shell command can I run from within the web app to automatically get my laptop's IP address to use things like scp ? I know how to get my IP address, but I'd like to create a program that will automatically enable scp for whoever uses it.

You have ssh access so you could possibly write a python function that would let you transfer files via scp the secure copy command which uses ssh to communicate. If you exchange keys with the server you wouldn't have to put in a password so I see no problem from that standpoint. The issue is if you have an address for your local machine to be accessed from the server.

I work on various remotes from my laptop all day and from my laptop to the sever I could have this function:

 def scp_to_server(address, local_file, remote_file):
      subprocess.call(['scp',local_file,"myusername@{}:{}".format(address, remote_file)])

that would copy a file from my local machine to the remote provided the paths were correct, I have permissions to copy the files, and my local machine's id_rsa.pub key is in the ~/.ssh/authorized_keys file on the remote.

I have no way to initiate a secure copy from the remote to my local machine however because I don't have an address to access the local machine from that I can "see" on the remote.

If I open the terminal on my laptop and run hostname I see mylaptop.local and on the remote I see remoteserver@where.i.work.edu but the first is a local address I can see it from other machines on my LAN at home, (because I have configured that) but I can't see mylaptop.local from the remote. I know there is a way to configure that so I could find my laptop at home from anywhere, but I never had the need to do that (since I bring the laptop with me) so I can't help you there. I think there are a few more hurdels to go-over than you would like.

You could implement the function above on your local machine and transfer the files that way though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM