With the latest version of Visual Studio Code it's now possible to remotely connect to a Linux host over SSH and gain a full access to it. One can access all files and access the shell within the IDE just like the user were working directly on the remote HOST.
Users can conveniently forward local ports to the remote Host, that is, services running on the remote host can be accessed using the local computer.
In case the user is a full-stack developer, for example, developing with Angular 2/x and Django, the user is probably running the following commands:
- ng serve (Listens on localhost:4200)
- python manage.py runserver (Listens on localhost:8000)
Occasionally when the user gets disconnected from the remote host (SSH is pretty sensitive stuff) these processes tend to survive the disconnect and they keep running. However, after reconnecting via SSH again, the user won't be able to easly get back to that shell. The easiest way is killing those two processes and execute them again.
The following files in this GIST automate this process:
/opt/on_logon.sh
Discovers the PID of processes listening on port [4200
,8000
] and kills them./etc/pam.d/sshd
executeson_logon.sh
on each new SSH connection, but not on each new shell creation.
- Create a new file called
on_logon.sh
in your filesystem, for example, in/opt
.
Paste the contents (see later in this gist) and make the file executablechmod +x /opt/on_logon.sh
- Add a new line to the end of
/etc/pam.d/sshd
:
session optional pam_exec.so seteuid /opt/on_logon.sh
- Done