Ssh Remote Port Forwarding

2 07 2018

First of all, check in the remote host the option “GatewayPorts yes” is enabled in “/etc/sshd/sshd_config“.
That is the switch that specifies whether remote hosts are allowed to connect to ports forwarded for the client, because, by default, sshd binds remote port forwardings to the loopback address only.

An then, execute the following commando to forward a remote tcp port from a remote server to a local server:

# ssh -NR 8080:localhost:80 user@remote.host

Test it, for example, if you have a local web server running on port :80:

# curl http://remote.host:8080

More info:
https://www.ssh.com/ssh/tunneling/example#sec-Remote-Forwarding

Advertisements




Display system uptime in a website

15 06 2018

Here are the steps to set up a simple website which shows the uptime values of a system.

First of all, install the requirements. Tuptime for monitor the system, apache as web server and php for the web. The web server can be nginx as well, their only requirement is that has to be able to work with php.
apt-get install tuptime apache2 php

Go to the document root location of the webserver and download the web file from the offical repo:
cd /var/www/html/
wget https://raw.githubusercontent.com/rfrail3/tuptime/master/misc/web/sample-wrapper-tuptime.php -O tuptime.php

That’s all, use a web browser to open the following url and view it:
http://127.0.0.1/tuptime.php

Uptime web





Python script who generates threads

5 01 2018

#!/usr/bin/env python3
import time
from threading import Thread
num_threads = 100
sleep_secs= 60
def create_thread(i):
print "Sleeping "+ str(sleep_secs) +" secs - Thread %d \n" % i
time.sleep(sleep_secs)
for i in range(num_threads):
t = Thread(target=create_thread, args=(i,))
t.start()
print "End"

View threads in top pressing “H”
View threads in ps with “-T”





Install VMware Horizon Client in Debian 8 Jessie

24 02 2017

Download the linux client from the VMware website:

https://my.vmware.com/en/web/vmware/info/slug/desktop_end_user_computing/vmware_horizon_clients/4_0

The downloaded file is a bash script, execute it from a privileged user:

# bash VMware-Horizon-Client-4.3.0-4710754.x64.bundle

Install dependencies:

# apt-get install libudev-dev libffi-dev libglibmm-2.4-dev

Before finish the install, click into the “Scan” button. If libffi.so.5 is missing and you have libffi.so.6 only (usually in a modern Debian), create a symlink for bypass:

cd /usr/lib/x86_64-linux-gnu && ln -s libffi.so.6 libffi.so.5

Probably, if you execute now the client, it doesn’t start because the following:

$ vmware-view
/usr/lib/vmware/view/bin/vmware-view: error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory

Solve that creating a simlink:

# cd /lib/x86_64-linux-gnu && ln -s libudev.so.1 libudev.so.0

And run!:

$ vmware-view





Ssh error Too many authentication failures for root

8 02 2017

ssh -o PubkeyAuthentication=no root@host





Install OpenLDAP in Debian 8

21 12 2016

This guide is the best, by far, that covers the installation of a LDAP server and the configuration of the loging of a server through it.

https://www.unixmen.com/install-openldap-in-ubuntu-15-10-and-debian-8/

http://www.unixmen.com/configure-linux-clients-to-authenticate-using-openldap/





Split Haproxy configuration in multiple files working with Systemd

9 12 2016

Splitting Haproxy configuration in multiple files it’s a bit tricky due the Systemd startup behaviour. One workaround who works ok it’s the following:

1.- Split the Haproxy configuration file in multiple files.

1.1.- One file called “00-haproxy.conf” with the basic haproxy conf (in my case global, defaults and listen stats). This must have the 00- at the begining for listed it at first place in the script.

1.2.- One file for each listen section for the different services balanced, “some_name_a.conf”. Each new balanced service will have a new file.

Note: In this case, each balanced service is inside a listen section, not using fronted and backed.

# ls /etc/haproxy/
00-haproxy.conf service1.conf service2.conf

# cat /etc/haproxy/00-haproxy.conf
global
...
defaults
...
listen proxy-stats
...
# cat /etc/haproxy/corebalv1.conf
listen xxx
bind ...
server ...
server ...

2.- Create a small script into “/usr/local/bin/haproxy-multiconf” with this content:

#!/bin/bash
for file in /etc/haproxy/*.conf; do
test -f $file
CNF="$CNF -f $file"
done
echo "CONF='$CNF'" > /etc/haproxy/haproxy-multiconf.lst

3.- Create a new systemd unit for create the conf list before launching the main Haproxy unit.
# cat /etc/systemd/system/haproxy-multiconf.service
[Unit]
Description=HAProxy Load Balancer Multiconf
After=network.target
Before=haproxy.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/haproxy-multiconf
[Install]
WantedBy=multi-user.target

4.- Modify the default systemd unit file of Haproxy:
# cat haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=network.target
Requires=haproxy-multiconf.service
[Service]
EnvironmentFile=/etc/haproxy/haproxy-multiconf.lst
ExecStartPre=/usr/local/sbin/haproxy -c -q $CONF
ExecStart=/usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid $CONF
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
[Install]
WantedBy=multi-user.target

5.- Refresh systemd and run it:

systemctl daemon-reload
systemctl restart haproxy.service