<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://teagom.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://teagom.github.io/" rel="alternate" type="text/html" /><updated>2024-09-24T15:02:07+00:00</updated><id>https://teagom.github.io/feed.xml</id><title type="html">Tiago SM</title><subtitle>Bookmark this to keep update!</subtitle><author><name>Tiago de Souza Moraes</name></author><entry><title type="html">Counting number of times each IP address appears in log file.</title><link href="https://teagom.github.io/2024/09/24/counting-number-of-times-each-IP-address-appears-in-log-file.html" rel="alternate" type="text/html" title="Counting number of times each IP address appears in log file." /><published>2024-09-24T00:00:00+00:00</published><updated>2024-09-24T00:00:00+00:00</updated><id>https://teagom.github.io/2024/09/24/counting-number-of-times-each-IP-address-appears-in-log-file</id><content type="html" xml:base="https://teagom.github.io/2024/09/24/counting-number-of-times-each-IP-address-appears-in-log-file.html"><![CDATA[<h2 id="how-to-print-a-total-of-hits-per-ip">How to print a total of hits per IP?</h2>

<p>I will use the common log of apache2</p>
<pre><code>/var/log/apache2/access.log
</code></pre>

<p>This is the format of access.log, I want to print total of hits per IP.</p>
<pre><code>192.168.0.x - - [24/Sep/2024:02:03:55 -0300] "GET / HTTP/1.1" 200
</code></pre>

<h2 id="to-explain-parts-of-last-command-line">To explain parts of last command line</h2>

<p>1 print only IP column</p>
<pre><code>cd /var/log/apache2
more access.log | awk '{print $1}'
# output
89.208.11.10
45.148.10.242
95.214.55.138
45.148.10.242
</code></pre>

<p>2 sort IP list</p>
<pre><code>more access.log | awk '{print $1}' | sort
# output
89.208.11.y
89.208.11.y
89.208.11.y
95.214.55.x
95.214.55.x
95.214.55.x
95.214.55.x
</code></pre>

<p>3 counter total of hits per IP</p>
<pre><code>more access.log | awk '{print $1}' | sort | uniq -c
# output
 1 141.98.11.122
 1 178.211.139.188
 2 185.16.39.118
 1 185.224.128.47
 1 35.177.209.183
98 45.148.10.242
 1 45.84.89.2
 1 46.174.191.30
 1 52.228.160.228
 2 5.8.11.202
 3 65.49.20.67
 1 79.124.59.226
 1 79.124.8.107
 1 81.17.22.122
 1 82.157.247.165
 2 89.190.156.137
10 89.208.11.10
30 95.214.55.138
 2 95.214.55.43
</code></pre>

<h2 id="custom-filter">Custom filter</h2>
<p>Filter 40x apache2 error, counter total of hits per IP.</p>
<pre><code>more access.log | grep '\" 40[0|1|2|3|4]' | awk '{print $1}' | sort | uniq -c
</code></pre>

<p>Filter 200 apache2 success, counter total of hits per IP.</p>
<pre><code>more access.log | grep '\" 200' | awk '{print $1}' | sort | uniq -c
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[How to print a total of hits per IP?]]></summary></entry><entry><title type="html">Basic commands and tools</title><link href="https://teagom.github.io/2024/09/19/basic-commands-tools.html" rel="alternate" type="text/html" title="Basic commands and tools" /><published>2024-09-19T00:00:00+00:00</published><updated>2024-09-19T00:00:00+00:00</updated><id>https://teagom.github.io/2024/09/19/basic-commands-tools</id><content type="html" xml:base="https://teagom.github.io/2024/09/19/basic-commands-tools.html"><![CDATA[<h3 id="merge-pdf-files">Merge PDF files</h3>
<pre><code>gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf  rg2020.pdf rg2020-ver.pdf 
</code></pre>

<h3 id="how-to-print-a-total-of-register-from-a-table-total-count-in-postgresql">How to print a total of register from a table? Total COUNT in postgreSQL.</h3>
<p>To create a file with the follow content:</p>
<pre><code>echo "SELECT COUNT(*) FROM client_client WHERE confirmed=1;"  &gt; /tmp/command.sql
</code></pre>
<p>Print date time and total of occurences 5 to 5 minutes, sleep command work’s in seconds,
crtl+c to out. Execute the command as postgres user.</p>
<pre><code>su - postgres 
while [ -z ]; do date &amp;&amp; psql -d mydatabase &lt; command.sql; sleep 300; done
</code></pre>

<h3 id="the-best-traffic-monitoring">The best traffic monitoring</h3>
<pre><code>iptraf-ng
</code></pre>

<h3 id="my-current-ip-address-via-line-command">My current IP address via line command</h3>
<pre><code>curl checkip.amazonaws.com
curl ifconfig.me
curl icanhazip.com
curl ipecho.net/plain
curl ifconfig.co
</code></pre>

<h3 id="show-resume-of-process-and-use-memory-for-each-service">Show resume of process and use memory for each service</h3>
<pre><code>https://github.com/pixelb/ps_mem
git clone https://github.com/pixelb/ps_mem.git
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[Merge PDF files gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf rg2020.pdf rg2020-ver.pdf]]></summary></entry><entry><title type="html">How to restrict commands for a SSH connection use authorized key?</title><link href="https://teagom.github.io/2024/09/19/how-to-restrict-commands-for-a-ssh-connection-use-authorized-key.html" rel="alternate" type="text/html" title="How to restrict commands for a SSH connection use authorized key?" /><published>2024-09-19T00:00:00+00:00</published><updated>2024-09-19T00:00:00+00:00</updated><id>https://teagom.github.io/2024/09/19/how-to-restrict-commands-for-a-ssh-connection-use-authorized-key</id><content type="html" xml:base="https://teagom.github.io/2024/09/19/how-to-restrict-commands-for-a-ssh-connection-use-authorized-key.html"><![CDATA[<p>In this case developers can only run git commands!</p>
<pre><code>git commit
git pull
git clone
git push
</code></pre>

<p>Developer computer is authorized for ssh connection but allow only git commands, any other bash/sh command will be dropped.
In order to limit the user to a single command, the parameter command = is entered before the key.</p>

<p>To create this file /home/user/.ssh/gitcommads, content:</p>
<pre><code>#!/bin/sh
exec git-shell -c "$SSH_ORIGINAL_COMMAND"
</code></pre>

<p>Set permission do exec</p>
<pre><code>chmod +x /home/user/.ssh/gitcommads
</code></pre>

<p>To edit /home/user/.ssh/authorized_keys and add commands before pub key.</p>
<pre><code># admin
ssh-rsa this-my-priv-key-admin.....
# dev 1
command="~/.ssh/gitcommands",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa this-my-priv-key-C00001......
# dev 2
command="~/.ssh/gitcommands",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa this-my-priv-key-C00002......
# dev 3
command="~/.ssh/gitcommands",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa this-my-priv-key-C00003......
</code></pre>

<p>To test you have to use ssh from developer computer to test!</p>
<pre><code>git clone ssh://login@server:/path
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[In this case developers can only run git commands! git commit git pull git clone git push]]></summary></entry><entry><title type="html">Docs</title><link href="https://teagom.github.io/2024/09/19/links-to-docs.html" rel="alternate" type="text/html" title="Docs" /><published>2024-09-19T00:00:00+00:00</published><updated>2024-09-19T00:00:00+00:00</updated><id>https://teagom.github.io/2024/09/19/links-to-docs</id><content type="html" xml:base="https://teagom.github.io/2024/09/19/links-to-docs.html"><![CDATA[<h2 id="monitoring-process-cpu-e-memory">Monitoring process, cpu e memory</h2>
<p>https://www.linuxtechi.com/generate-cpu-memory-io-report-sar-command/
https://www.thegeekstuff.com/2011/03/sar-examples/
https://www.thegeekstuff.com/2014/11/pidstat-examples/
https://www.tecmint.com/sysstat-commands-to-monitor-linux/
https://promet.github.io/2009/06/tracing-memory-leaks-with-pidstat/</p>

<h2 id="aws-cloudwatch-custom-log">AWS cloudWatch custom log</h2>
<p>https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/service_code_examples.html
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/ExtractBytesExample.html
https://docs.aws.amazon.com/pt_br/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html</p>

<h2 id="apache2">Apache2</h2>
<p>https://linuxbeast.com/tutorials/aws/how-to-export-logs-from-apache2-web-server-to-amazon-cloudwatch/
https://aws.amazon.com/blogs/mt/simplifying-apache-server-logs-with-amazon-cloudwatch-logs-insights/</p>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[Monitoring process, cpu e memory https://www.linuxtechi.com/generate-cpu-memory-io-report-sar-command/ https://www.thegeekstuff.com/2011/03/sar-examples/ https://www.thegeekstuff.com/2014/11/pidstat-examples/ https://www.tecmint.com/sysstat-commands-to-monitor-linux/ https://promet.github.io/2009/06/tracing-memory-leaks-with-pidstat/]]></summary></entry><entry><title type="html">PFSense commands</title><link href="https://teagom.github.io/2024/09/19/pfsense-commands.html" rel="alternate" type="text/html" title="PFSense commands" /><published>2024-09-19T00:00:00+00:00</published><updated>2024-09-19T00:00:00+00:00</updated><id>https://teagom.github.io/2024/09/19/pfsense-commands</id><content type="html" xml:base="https://teagom.github.io/2024/09/19/pfsense-commands.html"><![CDATA[<h2 id="easy-and-direct-commands-for-pfsense-and-freebsd">Easy and direct commands for PFSense and FreeBSD</h2>

<p>The following command adds a firewall rule, allowing tcp traffic in on port 443 from remote IP XX.XX.XX.XX: to the WAN IP on YY.YY.YY.YY:</p>
<pre><code>easyrule pass wan tcp XX.XX.XX.XX YY.YY.YY.YY 443
</code></pre>
<p>You can also allow SSH access and set up a remote port forward (ssh -L localport:remoteip:remoteport remoteip):</p>
<pre><code>easyrule pass wan tcp XX.XX.XX.XX YY.YY.YY.YY 22
</code></pre>

<p>Traffic network</p>
<pre><code>iftop -i re0 -F -P -o 2s
</code></pre>

<h2 id="nginx-dont-start-service-nginx-one-restart">Nginx don’t start, service nginx one restart</h2>
<p>erro</p>
<pre><code>Performing sanity check on nginx configuration:
nginx: [emerg] cannot load certificate key "/usr/local/etc/nginx/cert.key": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/usr/local/etc/nginx/cert.key','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
</code></pre>
<p>to fix</p>
<pre><code>cd /usr/local/etc/nginx
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout cert.key -out cert.pem -days 3650
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[Easy and direct commands for PFSense and FreeBSD]]></summary></entry><entry><title type="html">Facebook bots flooding a web server, how to block?</title><link href="https://teagom.github.io/2024/08/08/facebook-bots-hexcode.html" rel="alternate" type="text/html" title="Facebook bots flooding a web server, how to block?" /><published>2024-08-08T00:00:00+00:00</published><updated>2024-08-08T00:00:00+00:00</updated><id>https://teagom.github.io/2024/08/08/facebook-bots-hexcode</id><content type="html" xml:base="https://teagom.github.io/2024/08/08/facebook-bots-hexcode.html"><![CDATA[<p>A excessive / massive requests from facebook are flooding a web (apache2) server and freeze it for each 30 minutes.</p>

<p>Doubts</p>
<ol>
  <li>Why hex code found in the URL? Exploit memory address?</li>
  <li>Why massive and excessive requests?</li>
  <li>Are facebook-bots or attacker are using the game/app dev environment of facebook to do this?</li>
  <li>Bad robot?</li>
</ol>

<p><code>/var/log/apache2/access.log</code></p>
<pre><code>173.252.107.x - - [01/Aug/2024:10:20:45 -0300] "GET
index?q=\xe7\xbb\x8d\xe5\x85\xb4\xe5\x93\xaa\xe9\x87\x8c\xe6\x9c\x89\xe6\x9c
HTTP/1.1" 200 3847 "-" "facebookexternalhit/1.1
(+http://www.facebook.com/externalhit_uatext.php)"
</code></pre>

<p>Count hits daily of apache access log</p>
<pre><code>10.491 28/Jul/2024 without rule
 8.859 29/Jul/2024 without rule
 9.340 30/Jul/2024 without rule
 3.573 31/Jul/2024 without rule
 1.238 01/Aug/2024 with rule, 237 blocked IPs from 12h00 until 17h25.
</code></pre>

<p>To block, add this rule in the fail2ban service.</p>

<p><code>/etc/fail2ban/filter.d/apache-facebook-hexcode.conf</code></p>
<pre><code># Generic configuration items (to be used as interpolations) in other
# apache filters.
[Definition]
datepattern = ^[^\[]*\[({DATE})
failregex   = ^&lt;HOST&gt; -.*(GET|POST|HEAD).*\\x[a-zA-Z0-9].*$
              ^&lt;HOST&gt; -.*facebookexternalhit.*$
              
ignoreregex =
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[A excessive / massive requests from facebook are flooding a web (apache2) server and freeze it for each 30 minutes.]]></summary></entry><entry><title type="html">Instalando o PHL 8.2</title><link href="https://teagom.github.io/2024/07/19/instalando-phl-82.html" rel="alternate" type="text/html" title="Instalando o PHL 8.2" /><published>2024-07-19T00:00:00+00:00</published><updated>2024-07-19T00:00:00+00:00</updated><id>https://teagom.github.io/2024/07/19/instalando-phl-82</id><content type="html" xml:base="https://teagom.github.io/2024/07/19/instalando-phl-82.html"><![CDATA[<h2 id="instalando-e-configurando-sistema-phl---personal-home-library">Instalando e configurando sistema PHL - Personal Home Library</h2>

<p>Autor e download do PHL - http://www.elysio.com.br</p>

<p>BibliotecaPHL é um sistema para gerenciar uma biblioteca, empréstimo, consulta, cadastros e tudo aquilo que uma biblioteca necessita para funcionar. Aqui mostro como instalar o PHL, não tenho conhecimento de como gerenciar o sistema, banco de dados, usuários, livros e outros.</p>

<p>Todos os passos a seguir deve ser feito com usuário ROOT ou ter acesso sudo.</p>

<p><strong><em>Não funciona em 64Bits porque arquivos foram compilados em 32bits.
As informações inseridas em arquiterura 64 ficam todas bagunçadas,
sem nenhum sentido de leitura.</em></strong></p>

<p>Ambiente</p>
<pre><code>Linux Debian Lenny Arquitetura 32Bits ou 686.
Apache2 e PHL82

Diretório que vamos usar para descompactar o tar.gz do PHL
/usr/local/src/

Diretorio padrao Apache2, Document Root  
/var/www

Diretorio CGI do apache2
/usr/lib/cgi/bin

Diretorio do PHL dentro do apache2
/var/www/http

Download http://www.elysio.com.br/site/downloads.html
</code></pre>

<p>Instalar o apache2 e ligar/carregar o modulo CGI.</p>
<pre><code>apt-get update
apt-get install apache2
a2enmod cgid
</code></pre>

<p>Pacotes instalados no sistema, pode usar o comando:</p>
<pre><code>dpkg -l | grep -i apache
ii  apache2 2.2.11-2ubuntu2.5   Apache HTTP Server metapackage
ii  apache2-mpm-prefork   2.2.11-2ubuntu2.5   Apache HTTP Server - traditional non-threade
ii  apache2-utils 2.2.11-2ubuntu2.5  utility programs for webservers
ii  apache2.2-common    2.2.11-2ubuntu2.5    Apache HTTP Server common files
ii  libapache2-mod-php5    5.2.6.dfsg.1-3ubuntu4.4 server-side, HTML-embedded scripting languag
ii  libapr1    1.2.12-5ubuntu0.1    The Apache Portable Runtime Library
ii  libaprutil1    1.2.12+dfsg-8ubuntu0.3   The Apache Portable Runtime Utility Library
</code></pre>

<h2 id="instalação">Instalação</h2>
<p>vamos para o diretorio src</p>
<pre><code>cd /usr/local/src
</code></pre>

<p>Faça o download do pacote mais novo no site do fabricante com wget</p>
<pre><code>wget -c http://www.elysio.com.br/downloads/phl82_090619.tar.gz
</code></pre>

<p>vamos descompactar o pacote:</p>
<pre><code>tar zxfv phl82_090619.tar.gz
</code></pre>

<p>um diretorio “http” foi criado, é o conteudo do PHL. Vamos copia-lô  para o diretorio www do apache para que fique acessivel pelo navegador.</p>
<pre><code>cp /usr/local/src/http /var/www/. -prav
cd /var/www/http
</code></pre>

<p>Inicie o apache2</p>
<pre><code>/etc/init.d/apache2 start
</code></pre>

<p>Vamos editar o arquivo cgi-bin/phl82.cip para alterar os caminhos dos arquivos do PHL, vamos colocar o caminho completo nas configurações.Para isso vamos usar o comando <strong><em>sed</em></strong>.Os camandos abaixo fazem essas  alterações.</p>

<p>Faça uma copia do arquivo phl82.cip</p>
<pre><code>cp -prav cgi-bin/phl82.cip cgi-bin/phl82.cip.original
</code></pre>

<p>Alterando o original para o caminho do diretorio apache.</p>
<pre><code>more cgi-bin/phl82.cip.original | sed s/http/'var\/www\/http'/g &gt; cgi-bin/phl82.cip
</code></pre>

<p>O conteudo original do arquivo</p>
<pre><code>phl_*=/http/bases/phl_*
actab=/http/bases/actab
uctab=/http/bases/uctab
menu*=/http/www/phl82/html/menu*
cabe*=/http/www/phl82/html/cabe*
mens*=/http/www/phl82/html/mens*
rest*=/http/www/phl82/html/rest*
inde*=/http/www/phl82/html/inde*
logo*=/http/www/phl82/html/logo*
atra*=/http/www/phl82/php/mail_lote/atra*
aler*=/http/www/phl82/php/mail_lote/aler*
disp*=/http/www/phl82/php/mail_lote/disp*
usua*=/http/www/phl82/php/mail_lote/usua*
phl.css=/http/www/phl82/css/phl.css
tab_*=/http/cgi-bin/phl82/tabs/tab_*
</code></pre>

<p>como deve ficar</p>
<pre><code>00*=/var/www/http/bases/00*
phl_*=/var/www/http/bases/phl_* actab=/var/www/http/bases/actab
uctab=/var/www/http/bases/uctab
menu*=/var/www/http/www/phl82/html/menu*
cabe*=/var/www/http/www/phl82/html/cabe*
mens*=/var/www/http/www/phl82/html/mens*
rest*=/var/www/http/www/phl82/html/rest*
inde*=/var/www/http/www/phl82/html/inde*
logo*=/var/www/http/www/phl82/html/logo*
atra*=/var/www/http/www/phl82/php/mail_lote/atra*
aler*=/var/www/http/www/phl82/php/mail_lote/aler*
disp*=/var/www/http/www/phl82/php/mail_lote/disp*
usua*=/var/www/http/www/phl82/php/mail_lote/usua*
phl.css=/var/www/http/www/phl82/css/phl.css
tab_*=/var/www/http/cgi-bin/phl82/tabs/tab_*
</code></pre>

<p>Verifique se o arquivo foi alterado corretamente:</p>
<pre><code>more cgi-bin/phl82.cip
</code></pre>

<p>Feito isso, vamos criar um link do PHL para o diretorio CGI do apache:</p>
<pre><code>ln -s /var/www/http/cgi-bin/* /usr/lib/cgi-bin/.
</code></pre>

<p>Vamos criar outro link, do PHL82 para a raiz do diretorio apache, assim deixamos o sistema PHL acessivel pelo navegador.</p>
<pre><code>ln -s /var/www/http/www/phl82 /var/www/.
</code></pre>

<p>Permissão para o Apache2</p>
<pre><code>chown www-data.www-data /var/www/http -R
</code></pre>

<p>Agora já podemos acessar o PHL pelo navegador, http://ip_servidor/phl82/, se você quer acessar apenas o endereço do servidor e ir direto ao PHL82, faça o link do phl82/index.html para o document root do apache /var/www criando um simbolic link.</p>
<pre><code>ln -s http/www/phl82/index.html /var/www/. -f
</code></pre>

<p>Agora é só acessar o http://ip_servidor com o navegador que irá abrir diretamente o PHL82.</p>

<h2 id="erro-e-solução">Erro e solução</h2>
<hr />

<h3 id="erro-phl-82---indexhtml---valido">Erro PHL 82 - index.html - valido</h3>
<p>Nota sobre copyright contida no arquivo “index.html” foi violada!</p>

<p>Solução</p>
<pre><code>phl82.cip - caminho para diretorio está incorreto, verificar todos ou conteúdo do index.html foi alterado errado.
</code></pre>

<h3 id="erro-com-ubuntu-64bits">Erro com Ubuntu 64Bits</h3>
<p>Arquivo wxis.exe foi compilado em 32bits.</p>
<pre><code>tail -f /var/log/apache2/error.log 
[Tue Oct 16 13:36:58 2012] [error] (2)No such file or directory: exec of '/var/www/phl82/cgi-bin/wxis.exe' failed
[Tue Oct 16 13:36:58 2012] [error] [client 192.168.250.250] Premature end of script headers: wxis.exe, referer: http://172.0.0.1/phl82/
</code></pre>

<h3 id="erro-wxisfatal-error">Erro WXIS|fatal error</h3>
<pre><code>WXIS|fatal error|unavoidable|recread/xropn/w| 
usuario apache não tem permissão para ler arquivos
</code></pre>

<p><strong>Solução</strong>
Configurar permissão de dono aos arquivos para o usuario que executa o apache2,
normalmente é o user www-data.</p>
<pre><code>cd /var/www/http
chmod 755 bases -R
chown www-data:www-data bases -R
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[Instalando e configurando sistema PHL - Personal Home Library]]></summary></entry><entry><title type="html">OpenSSH - Custom settings for more security.</title><link href="https://teagom.github.io/2024/07/11/openssh-server-custom-settings.html" rel="alternate" type="text/html" title="OpenSSH - Custom settings for more security." /><published>2024-07-11T00:00:00+00:00</published><updated>2024-07-11T00:00:00+00:00</updated><id>https://teagom.github.io/2024/07/11/openssh-server-custom-settings</id><content type="html" xml:base="https://teagom.github.io/2024/07/11/openssh-server-custom-settings.html"><![CDATA[<p>For more security change ssh port for a custom port, but a risk to sshd broken and you can lost server ssh access.
To test a custom settings before to the production.</p>

<ol>
  <li>How to do this in safe mode?</li>
  <li>How to avoid to lost ssh connection?</li>
</ol>

<p>Enviromment</p>
<pre><code>Linux Ubuntu Server 20.04 64
Required root access / sudo
</code></pre>

<p>Make backup of sshd_config file</p>
<pre><code>cp /etc/ssh/sshd_config /etc/ssh/sshd_config.port22
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.port5000
</code></pre>

<p>You can run a second instance of openssh-server using a custom configuration, make all change you need.</p>
<pre><code>vim /etc/ssh/sshd_config.port5000
change port to 5000
Port 5000
</code></pre>

<p>To test the syntax of custom config file</p>
<pre><code>sshd -t -f /etc/ssh/sshd_config.port5000
</code></pre>

<p>Run a new server using new sshd_config, do not forget to open port at firewall.</p>
<pre><code>-4d: Ipv4 + debug
-f : config file
</code></pre>
<pre><code>/usr/sbin/sshd -4d -f /etc/ssh/sshd_config.port5000
</code></pre>
<p>ctrl+c to stop</p>

<p>Open a new terminal and try a ssh connection using port 5000 from authorized client.</p>
<pre><code>ssh user@server -p 5000
</code></pre>
<p>If you have success, then copy ssh_config.port5000 to sshd_config (default) and restart the service.
<strong>Try lot of times new connection before leaving your server!</strong></p>
<pre><code>cp /etc/ssh/sshd_config.port5000 /etc/ssh/sshd_config
sudo service ssh restart
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[For more security change ssh port for a custom port, but a risk to sshd broken and you can lost server ssh access. To test a custom settings before to the production.]]></summary></entry><entry><title type="html">How to convert lot of images?</title><link href="https://teagom.github.io/2024/07/10/convert-lot-of-images.html" rel="alternate" type="text/html" title="How to convert lot of images?" /><published>2024-07-10T00:00:00+00:00</published><updated>2024-07-10T00:00:00+00:00</updated><id>https://teagom.github.io/2024/07/10/convert-lot-of-images</id><content type="html" xml:base="https://teagom.github.io/2024/07/10/convert-lot-of-images.html"><![CDATA[<h3 id="this-text-explain-how-to-convert-lof-of-images-of-lot-of-folders">This text explain how to convert lof of images of lot of folders.</h3>

<p>Enviromment</p>
<ol>
  <li>Linux Ubuntu 20.04 64</li>
  <li>convert command, ImageMagick Package</li>
</ol>

<p>We will to use the <strong><em>convert</em></strong> command, bash, convert - https://packages.ubuntu.com/disco/graphicsmagick-imagemagick-compat
Install Image Magick</p>
<pre><code>apt install imagemagick
</code></pre>

<p>This is a sample</p>
<pre><code>cd /tmp/my-albuns
ls -la
drwxrwxr-x  2 user user    4096 Out  4 19:10 ci
drwxrwxr-x  2 user user    4096 Jul 12 16:07 eletrica
drwxrwxr-x  2 user user    4096 Out 13 19:11 componentes-diversos
</code></pre>

<p>set variables</p>
<pre><code>SIZE='50%'	# resize image to 50% of owner size
OUT='800'	# output to converted folder name, 800x600
</code></pre>

<p>What the script will do?</p>
<ol>
  <li>create a folder with name-800</li>
  <li>convert all images of folder to 50% of original size</li>
</ol>

<p><strong>F: Folder name</strong>
<strong>I: Image file</strong></p>
<pre><code>cd /tmp/my-albuns
SIZE='50%'
OUT='800'
for F in $(ls)
	do
	mkdir $F-$OUT
	for I in $(ls $F)
		do
		echo "+ $F/$I";
		convert -resize $SIZE $F/$I $F-$OUT/$I;
	done
done
</code></pre>

<p>output</p>
<pre><code>drwxrwxr-x  2 user user    4096 Out  4 19:10 ci
drwxrwxr-x  2 user user    4096 Out  4 19:10 ci-800
drwxrwxr-x  2 user user    4096 Jul 12 16:07 eletrica
drwxrwxr-x  2 user user    4096 Jul 12 16:07 eletrica-800
drwxrwxr-x  2 user user    4096 Out 13 19:11 componentes-diversos
drwxrwxr-x  2 user user    4096 Out 13 19:11 componentes-diversos-800
</code></pre>
<p><strong><em>Be carefull</em></strong> To Delete folder that contain 800 at end of name and all content.</p>
<pre><code>find . -name '*800' -exec rm -rf '{}' \;
</code></pre>]]></content><author><name>Tiago de Souza Moraes</name></author><category term="Other" /><summary type="html"><![CDATA[This text explain how to convert lof of images of lot of folders.]]></summary></entry></feed>