Start Teamviewer from an ssh session remotely

So you remote deskptop rebooted and teamviewer did not run on startup as it does not do in Linux for some strange reason:

Connect with ssh ( putty)

Then run

DISPLAY=`localhost`:0 teamviewer&

Njoy 🙂 !

SSH through HTTP proxy

This article explains how to connect to a ssh server located on the internet from a local network protected by a firewall through a HTTPS proxy.

Requirement are :

  • Your firewall has to allow HTTPS connections through a proxy
  • You need to have root access to the server where ssh is listening

Configure the ssh server

The ssh daemon need to listen on 443 port. To accomplish this, just edit this file (on debian system) /etc/ssh/sshd_config and add this line :

Port 443

Then restart the daemon :

sudo /etc/init.d/ssh restart

Configure the client

I suppose you are on a Linux system (debian for example). First you have to compile the connect binary which will help your ssh client to use proxies (HTTPS in our case). Then you have to configure your ssh client to tell him to use HTTPS proxy when he tries to connect to your ssh server.

  1. Install the connect software :
    • On debian system, just install the connect-proxy package :

      sudo apt-get install connect-proxy
    • On other Linux systems, you have to compile it :

      cd /tmp/
      wget http://www.meadowy.org/~gotoh/ssh/connect.c
      gcc connect.c -o connect
      sudo cp connect /usr/local/bin/ ; chmod +x /usr/local/bin/connect
  2. Configure your ssh client. Open or create your ~/.ssh/config file and add these lines :

    ## Outside of the firewall, with HTTPS proxy
    Host my-ssh-server-host.net
      ProxyCommand connect -H proxy.free.fr:3128 %h 443
    ## Inside the firewall (do not use proxy)
    Host *
       ProxyCommand connect %h %p
  3. Then pray and test the connection :

    ssh my-ssh-server-host.net

SSH to another server through the tunnel

For example to connect to in ssh github.com :

Host github.com
  ProxyCommand=ssh my-ssh-server-host.net "/bin/nc -w1 %h %p"

Sharing a screen SSH session

Sharing your Session

Assuming you start a screen session using

screen -S david

Ask your partner to connect using (assuming they are logged in using the same user account):

screen -x david

Now it’s simply magical. Multiple persons can type and work on the same terminal – it works best when you’re coordinating over the phone. Note that the dimensions of your terminal output will be the same for every user – to change it, press CtrlA and then capital F. This will make the screen output fit your current terminal size, and change it to that size for every connected user.

Detaching from a Screen Session

Important: To detach from the screen session so that you can resume later, simply close the window. If you typeexit, you’ll end up terminating the screen session and the processes running within.

Cool way to run a script on a remote machine

If you have a local script file and want to run the script on another server use the following :

ssh root@torino.maranello.local  ‘bash -s’ < script_local.sh

Enjoy 🙂

Tar a folder or entire system through ssh

We all had the problem of needing to backup a folder or an entire system from a machine before decommissioning or as a postfix backup solution only to find tarring aint gonna work cause you have very little space left. Also there are folders you want to avoid tarring since they contain logs or system virtual folders that you want to skip.

So you need to get a tar from a machine have very little space left and you need to pull all the files in a compressed fashion; the following command calls a backup as root through ssh using tar on the source machine and skips the folders you do not want :

ssh root@pollux "tar zcvf - --exclude=/proc/* --exclude=/dev/* --exclude=/sys/* --exclude=/var/logs/* /" > /root/backup/pollux.fullandfinal.$(date '+%Y-%m-%d-%k-%M').tar.gz

The result of the above command is a backup of the / compressed at source piped through console through ssh back to your local / backup repo machine in .tar.gz format leaving out the rubbish thanks to the :

- --exclude=/proc/* --exclude=/dev/* --exclude=/sys/* --exclude=/var/logs/*

section. Note the “– —” the first – indicates extended parameters and –except leaves out any match to the path.

There you go one command to back them all.

(this could be easily bash-ed and cron-ed to produce a decent makeshift backup tool.

To check out the contents of the tar file you can use

tar -tvzf <archive.tar.gz>

This will show you the contents and leave a fail exit code in a bash script.