Using multiple terminals on a remote machine using a single SSH connection - sockets

I'm running a process on a remote server through SSH on a certain port. The process is basically a TCP server waiting (listening) for a connection. So as long as it is running I cannot use the terminal as it is a blocking application.
I want to run another application (a TCP client) through the same instance of SSH connection to connect to that TCP server. I used screen to detach the first process (TCP Server) and connect to the server but then I could not see the output of the TCP server application.
Is there a way to emulate two terminals on a remote machine using SSH?

So I found a solution to this problem. Basically below is a link that explains how can I achieve exactly what I needed. That is, opening multiple terminals using a single SSH connection.
http://idnotfound.wordpress.com/2008/01/14/multiple-terminals-in-a-single-ssh-session/
In short we can use the following procedure:
$ ssh -X mylogin#remotemachine gnome-terminal
Password: ...
[Ctrl+Z]
$ bg
$ exit
Press Ctrl+Shift+N to open a new terminal.
EDIT: Or just use screen. Sigh..

Related

Avoid cancel of postgresql script when losing connection to server due to VPN session closing

I'm trying to execute a remote postgresql script by command line (connecting to the server via putty) by using
\i myscript.sql
The problem comes when the script takes several hours to complete and VPN connection to the server (and consequently putty session) close. I can't really control that part because it's a local security policy. The session closing makes the execution of the script to cancel.
Is there an easy way to let the script run in the server regardless I'm still connected to it?
After you putty in use GNU screen or one of its equivalents like tmux before you run psql. This will preserve your session when you get disconnected so you just reconnect to it next time you log in.
You can reduce the TCP keepalive idle time on your client operating system to have the client send “keepalive packets” regularly, which keeps the misconfigured firewall from closing the connection.
Start psql using the connection string syntax:
psql 'host=... port=5432 user=... dbname=... keepalives_idle=60s'

Nested ssh connection

I want to connect via ssh to the server and from this server connect to another server via ssh. Do you know if there are any extensions that would allow me to do so?
Can you just use
ssh -t userid1#machine1 "ssh userid2#machine2"
assuming that you have a ssh client on the first target?

How to do SSH tunneling with docker (machine & compose)?

I have a mongoDB container running on an instance built with docker-machine, maintained with docker-compose. The mongoDB process isn't exposed to external traffic.
I want to connect to the remote mongoDB server using a GUI tool installed locally and without exposing any ports on the remote machine.
What's the best way to do this? Is there any way I can tunnel the connection via ssh with the docker-machinie ssh command?
What's the best way to do this? Is there any way I can tunnel the
connection via ssh with the docker-machinie ssh command?
Yes. Per the docs, docker-machine invokes the standard OpenSSH client. You can use the same -L syntax that you'd normally use for SSH tunneling. The end of the doc has an example using port 8080.

Console pgAdmin-like software

I like the pgAdmin III GUI software, but the GUI uses more bandwidth than SSH console.
psql is not interactive, without menus, tables list, etc.
Does exist some interactive text-mode tool to connect to PostgreSQL ?
There is no text-mode window-and-menu curses/ncurses style text mode interface for PostgreSQL; no ncurses equivalent to PgAdmin-III.
I strongly recommend learning psql and getting comfortable with it. You could use PgAdmin-III remotely as detailed below, but in the long run you'll be massively more productive if you learn psql.
Use PgAdmin-III via ssh tunnels or direct connection
You can always connect with PgAdmin-III via an ssh tunnel or remote TCP/IP connection. That way you aren't transmitting all the GUI data over the network, just the PostgreSQL protocol data.
For ssh, do something like:
ssh -L 15432:localhost:5432 remote_host
then while the ssh session is open, connect to localhost port 15432 to make a connection to the remote DB.
This will work even if the remote DB is only listening on 127.0.0.1. It'll also work if you ssh into a bastion host then connect to the DB server from there; just change localhost in the -L argument to the IP/hostname of the Pg server. For more information see the ssh manual, particularly LocalForward for IP forwarding, ProxyCommand for custom multilayer tunnels, and the -D option for dynamic SOCKS proxying.
It's even possible to use an ssh tunnel to connect to a server that's only listening for unix socket connections, by running socat to proxy between the unix socket and TCP.
None of this will work when you're connecting to a Windows host, but rdp2tcp can be used to tunnel TCP over RDP connections for similar effect. See this question.
Use psql
psql is pretty interactive. Though it isn't a GUI windowing interface, it's hardly just a scripting tool. It provides lots of visibility into the system with the \d commands, lots of info via \h, tab completion, paging, \e break-out command editing, and lots of other interactive features.
Use \? for psql help, and \h SQL_COMMAND for syntax of a particular SQL command, eg \h INSERT.

Trying to connect to a remote server using Eclipse

I have an Ubuntu server running Tomcat, and I want to connect my Eclipse EE to it so I can work with JSP.
I have no problem connecting to a similar Tomcat service when it's installed on my machine (not a server), but whenever I try to connect to the remote server I don't seem to have the option of choosing a Tomcat service.
Is there some guide you can recommend (I didn't find one), or is there something I did wrong?
The "remote" Tomcat (or more generally the app server) must be configured to permit such connection.
Did you start the remote server with these parameters:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
Alternatively you can add the word jpda at the end of the startup.sh (or .bat) script just when calling the catalina.sh script.
Everything is documented on the Apache Tomcat Wiki.
After enabling those options, you have also another task to do: enabling the network connection to the configured port (8000 in the above options). It depends which firewall is installed on the server but usually it is iptables.
Example of iptables command to enable connection to port 8000:
sudo iptables -A INPUT -p tcp --dport 8000 -j ACCEPT
If your server have a GUI installed, one easiest way is to use the "ufw" – short for 'uncomplicated firewall' as explained in this site which is just a graphical way to configure the iptables.
One way to test the connectivity to the server (if the port is open) is to use telnet from your computer like this:
telnet your.distant.host 8000
and if the command opens, the port is accessible, if the telnet command times out, the port is closed.