When using ssh -X to connect to remote Ubuntu 18.04, couldn't it show server's local terminal GUI on my own PC? - ssh

I found a strange thing when using ssh -X to connect to two servers.
Ubuntu16.04 is installed on one server, while Ubuntu 18.04 is installed on the other. I upload a simple shell script as following to both servers:
#!/bin/bash
tab=" --tab"
options=()
cmds[1]="echo Banana"
cmds[2]="echo Cat"
for i in 1 2; do
options+=($tab -e "bash -c '${cmds[i]} ; bash'" )
done
gnome-terminal "${options[#]}"
exit 0
You know this script will open a new terminal window on server with two tabs. One tab will print "Banana", and the other tab will print "Cat".
Then I using ssh -X to remotely login into the first server (Ubuntu 16.04) and execute this script on server, I got a new terminal opened with two tabs on my pc. That is I saw the remote terminal GUI of server on my own computer. However, if I repeated these steps on the second server(Ubuntu18.04), I will got nothing to show on my computer.
The I execute commandgedit on the ssh login terminal when using ssh -X to login into both servers, I could see the GUI on my computer for both the cases.
I guess Ubuntu 18.04 cannot transport terminal's GUI through ssh -X to my pc. I was very confused about this. Could you please to explain the reason? And BTW, how can I see terminal's GUI of server in this case? Thanks a lot!

ssh -X doesn't transport a terminal. It tunnels a X11 connection.
X11 in its core is a network based display protocol. The programs (X clients) connect to a X server (a program running on your local machine) and instruct it to create windows and draw stuff to it. There is no graphical rendition of any kind anywhere else than the X server!
ssh -X does not operate like Windows Remote Desktop, where there is an actual graphics environment running on the remote machine. Hence if you create two separate ssh -X connections (maybe even from different machines), these connections are completely independent from each other. Hence you cannot use ssh -X to connect with a preexisting X session!
What you want is either Xvnc or Xpra, where the graphics environment is actually run on the remote machine, and only the output is transferred to your local machine.

Related

Does replit uses ssh?

Replit's terminal provides a lot of features that are very similar to any Linux terminal. At first, I thought the site was using SSH to link a remote terminal to the website but when I ran the following command service ssh status, then the output was
* sshd is not running. This indicates that the site is not using SSH to link the terminal.
Does this mean the developers have created a custom terminal for their website or is there a way to show this output for remote users for security purposes?

Cygwin X11 forwarding using Xming

i am connected with cygwin to a ssh server
there i want to open a application via x11-forwarding
i use xming as x11 server on my windows machine
now in putty i had the possibility to automatically forward x11 and so i dont need to export my DISPLAY, thats not a problem i can set it every time i connect to the server.
but if i export my DISPLAY, it wont start the application it always says:
Error: Can't open display: xxx.xx.xx.xx
i really liked the way putty worked and want to user cygwin.
i tried Cygwin/X but there always opens another terminal which i dont really like. i like to open my application from my existing standart cygwin terminal where i also connect to the server
is there any way doing this?!
i startet the xserver with the following command and after that i could start the programms automatically on my remote ssh server and it was forwarded automatically to my xserver
startxwin -- -listen tcp &
after this i even didnt have to set the DISPLAY

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.

How to exectute a Mathematica Script through ssh

here is my problem: i would like to run a Mathematica script through ssh on a remote machine so that i can close the terminal on my computer and keep it running on the remote one.
My problem arises because the script acts in interacting mode, and so when i close the terminal the process is shut down too.
Thanks.
Use tmux or GNU screen.
Workflow:
ssh into remote machine
start tmux/screen, e.g. tmux or screen
start Mathematica script inside tmux/screen session
detach tmux/screen session, e.g. Ctrl+B d (tmux) or Ctrl+A d (screen)
close ssh connection
Then later:
ssh into remote machine
reattach to tmux/screen session, e.g. tmux attach or screen -d -R
view completed Mathematica script output
Several cases:
If you don't need to interact with it or need to visualize the notebook during evaluation
Log in to the machine with ssh
Then, to run a kernel in the background and detach it from the current session, use nohup tool (the standard output of the command will be dumped to myNotebook.out):
nohup math < myNotebook.nb > myNotebook.out &
At this point, the ssh session can be closed without killing Mathematica
Optionally you can monitor mathcommand output with the tail command (use CTRL-C to exit the tail monitoring)
tail -f myNotebook.out
If you need to see what's going on, visualize graphs during calculation or to be able to interact graphically, use remote desktop (vnc) and tunnel your communication with remote machine. Details depends a bit on the Linux distribution (vnc clients & servers may differ). You can even from Windows or Mac connect with remote desktop to your linux box and manipulate it. I suggest you to search the web for remote desktop ssh tunnel + your distro for tutorials.

Run Octave remotely and display locally via X11

I'm currently implementing some machine learning algorithm by octave and run in the remote server. Once I type some drawing commands such like hist() it shows that
warning: X11 DISPLAY environment variable not set
Is it possible that I set the environment as my local X11 service. How to do it? Thanks.
Connect the remote server by ssh and add the option -X
ssh -X remote_server
Then ssh will enable X11 forwarding.