call a program from local terminal while in an ssh session - ssh

Is there some way to call on a local program while using an ssh connection to a remote host? I'd like to have access to the environment on both sessions, so opening another terminal isn't ideal.
Edit: specifically the uses would center around scp or local programs that use it (i.e. the emacs extension tramp). The two things I had in mind:
to be able to type download x.png on a remote machine and have the file pulled to my computer.
something like emacs-local file.py that would open emacs on my local computer and use tramp to edit file.py.

Related

How to remote SSH into a MacOS or Linux terminal using the Termius app?

I have been playing with the Termius app on Android running downloaded shell scripts that I wrote, catting files and snooping inside my device's directories; among other goofy stuff.
I have seen in some tutorials that I can remote SSH into my computer's terminal and run commands into my Android's Termius as if I'm typing on my computer's keyboard.
Having attempted these instructions myself, I've found they're no good (IMHO) and I couldn't make them work. Also, these tutorials have no good explanation for how I am actually SSHing using the Termius app.
The question is: How do I make it work and how does it work?
You would need to:
generate a key on Termius (and export it)
add that key to your Mac or Linux remote user ~/.ssh/authorized_keys
connect to the remote computer using ssh remoteUser#remoteIP
That assume you have an ssh daemon listening on that remote computer.

Can I run one WSL2 virtual machine instance on two system?

I'm new to the WSL2 and wondering if it's possible to run the same WSL2 ubuntu instance on both my desktop and laptop.
Now I am able to use wsl --export and wsl --import method to save and load the system to/from my portable hard drive. But these methods takes a long time.
I notice that wsl --import load a file named ext4.vhdx. Is there a way to load straightly from this file?
Update v2.0:
I was able to get a workaround and it works great.
Thanks to Booting from vhdx here, I was able to load straightly from my vhdx file on my portable hard disk. Windows track down its subsystem with regedit, So we can write our own(p.s: make sure to get BasePath right, it starts with "\\\\?", or you will not be able to access the subsystem' filesystem on your host system.):
Windows Registry Editor Version 5.00
[HKEY_USERS\【your SID here】\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{【UUID here】}]
"State"=dword:00000001
"DistributionName"="distribution name"
"Version"=dword:00000002
"BasePath"="vhdx folder path" 【 e.g. "\\\\?\\E:\\S061\\WSL\\ubuntu-20"】
"Flags"=dword:0000000f
"DefaultUid"=dword:000003e8
I suppose the best way to do this would be to store ext4.vhd on a network storage device accessible to both devices.
I have previosly mentioned how to move ext4.vhd. You can check that out here
Basically you need to export from one machine and import it while making sure the vhd file is configured for wsl to access from the network storage
Since this should *officially* not supported expect some performance hits
Another way would be to run WSL on one computer and ssh/remote desktop to it from another device on the network
I'm of the strong belief that sharing the same ext4 vhd between two VM's simultaneously would be a bad idea. See this and this Unix & Linux StackExchange, including the part about ...
note that sharing LVs/partitions on a single disk between the servers at the same time is NOT very safe. You should only access whole disks from any of the servers at one time.
However, as dopewind's answer mentioned, you can access the WSL instance on one computer (probably the desktop) from another (e.g. the laptop). There are several techniques you can use:
If you have Windows 10 Professional or Enterprise on one of the computers, you can enable Remote Desktop, which allows you to access pretty much everything on one computer from another. RDP ("Remote Desktop Protocol") even works from other devices such as an iPad or Android tablet (or even a phone, although that's a bit of a small screen for a "desktop"). That said, there are better, more idiomatic solutions for WSL ...
You could enable SSH server on the Windows 10 computer with the WSL instance (instructions). This may sound counterintuitive to some people, since Linux itself running in the WSL instance also includes an SSH server (by default). But by SSH'ing from (for example) your laptop into your desktop's Windows 10, you can then launch any WSL instance you have installed (if you choose to install more than one) via wsl -d <distroName>. You also avoid a lot of the network unpleasantness in the next option ...
You could, as mentioned above, enable SSH on the WSL instance (usually something like sudo service ssh start) and then ssh directly into it. However, note that WSL2 instances are NAT'd, so there's a whole lot more hackery that you have to do to get access to the network interface. There's a whole huge thread on the WSL Github about it. Personally, I'd recommend the "Windows SSH Server" option mentioned about to start out with, then you can worry about direct SSH access later if you need it.
Side note: Even though I have SSH enabled on my WSL instances, I still use Windows SSH to proxy to them, to avoid these networking issues.

Script for connecting to remote server (via another desktop) from my laptop using cygwin

I need to connect to my university server (S) from home using my laptop (L). Since I am off campus (and my VPN does not work for some reason), I am required to first login (SSH) to my desktop (D) at the university, and then connect to S (since the server only accepts connections from computers on the campus network).
I am using Cygwin on Windows 8. I would like to know how I can create a script to auotmate this process - currently I have to manually SSH from L to D, and then again from D to S. I am new to unix.
Any help will be appreciated. Thanks.
--- Edit ---
Specifically, I would like to know how I can automate this process so that I don't have to enter my password every time.
ssh accepts a command to execute at the remote host after connecting. You can use that to launch a second ssh session:
ssh -t D ssh S
You'll be prompted for your desktop password first, then for your server password.
By the way, I recommend looking into GNU screen if you're not already using it. It prevents losing any work in case your SSH connection drops out.
To automate this even more, stick it in a bash file called "connect-university.sh":
#!/bin/bash
ssh -t D ssh S
You can then run that file from the Cygwin commandline via:
./connect-univiersity.sh
Note that the ./ part is essential, as Cygwin doesn't usually look for executable files in the current directory for security reasons.

Access an xterm window open on local machine , remotely via ssh

I have an xterm window open on a computer. I want to access this xterm window remotely using ssh. Is it possible? By access I mean, I should be able to run commands on that open shell.
I'm not sure if it is possible to access an xterm window that's already been opened, while being over ssh. However, you can certainly open an ssh connection with X11 forwarding capabilities. Once X11 is forwarded, you can just run the program in ssh's command line, and it'll open in your forwarded X11 screen.
Here's a good article that explains in detail what you need to accomplish this: http://www.math.umn.edu/systems_guide/putty_xwin32.html
For example, after completing the details in the above article, and assuming you have Gnome Desktop installed, you could run gnome-terminal over ssh and have a Unix terminal open and forwarded over the ssh connection. Pretty much any application that has a GUI is runnable this way.

executing on a remote machine

The Setup
We have an aircon unit in the office but it takes a good hour to start cooling the place down, I have an IR USB device that communicates via a com port. I have a utility to send various IR codes to control an aircon unit.
I use .bat files to load the .exe and the .bin file
irtoy.exe -d COM4 -p -a 100 -f ACPowerToggle.bin
My question is what's the best way I can execute this on a remote server? Is it possible from a web server or something else?
I suggest using an SSH server like OpenSSH, as well as providing secure access, you can execute programs, manage everything needed as well as direct access to the computer's operating system.
Edit:
Yes, you can use both iOS and Android apps to access your SSH server using a smart phone.