1. INSTALAÇÃO E CONFIGURAÇÃO DO LXD
Para realizar todo o trabalho, foi necessário instalar o LXD na máquina.
Comandos utilizados:
# Atualizar os pacotes do sistema
sudo apt update && sudo apt upgrade -y
# Instalar o LXD (caso ainda não esteja instalado)
sudo apt install -y lxd
# Adicionar o usuário atual ao grupo lxd (para evitar usar sudo sempre)
sudo usermod -aG lxd $USER
# Iniciar a configuração do LXD
lxd init
ivaldo@Ivaldo:-$ /snap/bin/lxc list -c n4
+---+---+
| NAME | IPV4 |
+---+---+
| vitoria | 10.176.19.158 (eth0) |
+---+---+
Resumo da rede:
- Sua máquina real: 192.168.0.10
- Container "vitoria": 10.176.19.158
- Bridge LXD: 10.176.19.1
Para entrar no Container "vitoria":
lxc exec vitoria bash
2. SERVIÇO SSH
O que fizemos:
- Instalamos o servidor SSH: apt install openssh-server
- Ativamos o serviço SSH
- O SSH está funcionando na porta 22
- Permite acesso remoto e transferência de arquivos
Comandos usados:
# Instalação e configuração do SSH
apt install openssh-server -y
systemctl enable ssh
systemctl start ssh
root@vitoria:~# systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; preset: enabled)
Drop-In: /run/systemd/system/service.d
L-zzz-lxc-service.conf
Active: active (running) since Thu 2025-10-30 17:42:36 UTC; lh 31min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 168 (sshd)
Tasks: 1 (limit: 4603)
Memory: 1.0M
CPU: 50ms
CGroup: /system.slice/ssh.service
L_168 "sshd: /usr/sshn/sshd -D [listener] 0 of 10-100 startups"
Oct 30 17:42:36 vitoria.lab systemd[1]: Starting ssh.service - OpenBSD Secure Shell server...
Oct 30 17:42:36 vitoria.lab sshd[168]: Server listening on 0.0.0.0 port 22.
Oct 30 17:42:36 vitoria.lab sshd[168]: Server listening on :: port 22.
Oct 30 17:42:36 vitoria.lab systemd[1]: Started ssh.service - OpenBSD Secure Shell server.
root@vitoria:~#
Acesso SSH funcionando:
Print do comando da Maquina Real para o Container: ssh root@10.176.19.158 funcionando
Arquivo Editar Exibir Pesquisar Terminal Ajuda
ivaldo@lvaldo:-$ ssh root@10.176.19.158
Linux vitoria.lab 6.12.48+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.48-1 (2025-09-20) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
root@vitoria:-#
Print do comando do Container para Maquina Real: ssh ivaldo@192.168.0.10 funcionando
Arquivo Editar Exibir Pesquisar Terminal Ajuda
root@vitoria:-# ssh ivaldo@192.168.0.10
ivaldo@192.168.0.10's password:
Linux lvaldo 6.12.48+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.48-1 (2025-09-20) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
Last login: Fri Oct 31 09:09:18 2025 from 10.176.19.158
ivaldo@lvaldo:-$
Transferência de arquivos com SCP:
# Criar arquivos de teste
mkdir transferencia_teste
echo "Arquivo A" > transferencia_teste/a.txt
echo "Arquivo B" > transferencia_teste/b.txt
echo "Conteúdo do arquivo de teste para SCP" > teste_transferencia.txt
# Verificar transferência
ssh root@10.176.19.158 "ls -la /tmp/teste_transferencia.txt/tmp/pasta_teste/"
Arquivo Editar Exibir Pesquisa Terminal Ajuda
cp: não foi possível obter estado de 'arquivo': Arquivo ou diretório inexistente
ivaldo@lvaldo:-$ scp arquivo root@10.176.19.158/home/
cp: não foi possível obter estado de 'arquivo': Arquivo ou diretório inexistente
ivaldo@lvaldo:-$ mkdir pasta teste
ivaldo@lvaldo:-$ echo "Arquivo 1" > pasta_teste/arquivo1.txt
ivaldo@lvaldo:-$ echo "Arquivo 2" > pasta_teste/arquivo2.txt
ivaldo@lvaldo:-$ scp teste_transferencia.txt root@10.176.19.158:/tmp/
scp: stat local "teste_transferencia.txt": No such file or directory
ivaldo@lvaldo:-$ echo "Conteúdo do arquivo de teste para SCP" > teste_transferencia.txt
ivaldo@lvaldo:-$ scp teste_transferencia.txt root@10.176.19.158:/tmp/
teste_transferencia.txt 100% 39 18.9KB/s 00:00
ivaldo@lvaldo:-$ scp -r pasta_teste/ root@10.176.19.158:/tmp/
arquivo2.txt 100% 10 4.5KB/s 00:00
arquivo1.txt 100% 10 27.6KB/s 00:00
ivaldo@lvaldo:-$ ssh root@10.176.19.158 "ls -la /tmp/teste_transferencia.txt /tmp/pasta_teste/"
-rM-r--r-- 1 root root 39 Oct 31 12:37 /tmp/teste_transferencia.txt
/tmp/pasta_teste/:
total 8
dnxrwxr-x 1 root root 48 Oct 31 12:38 .
dnxrwxrwt 1 root root 632 Oct 31 12:38 .
-rM-r--r-- 1 root root 10 Oct 31 12:38 arquivo1.txt
-rM-r--r-- 1 root root 10 Oct 31 12:38 arquivo2.txt
ivaldo@lvaldo:-$
Configuração de Acesso sem Senha com Chave SSH:
Passo 1: Configurar SSH no Container
nano /etc/ssh/sshd_config
Verificar configuração:
PasswordAuthentication yes
PermitRootLogin yes
Reiniciar serviço: systemctl restart ssh
Passo 2: Na SUA MÁQUINA, gerar chave SSH
ssh-keygen -t rsa -b 4096 -C "ivaldo@ifrn"
# (Pressione Enter 3 vezes - sem senha na chave)
Passo 3: Copiar chave para o container
ssh-copy-id root@10.176.19.158
# (Vai pedir a senha do root do container - dígite a senha)
Passo 4: Testar acesso SEM SENHA
ssh root@10.176.19.158
# (Agora deve entrar sem pedir senha!)
Passo 5: Desativar login com senha (opcional)
No container:
nano /etc/ssh/sshd_config
Mudar para:
PasswordAuthentication no
Reiniciar: systemctl restart ssh
Verificação final:
lxc exec vitoria bash
cat /etc/ssh/sshd_config | grep PasswordAuthentication
Arquivo Editar Exibir Pesquisar Terminal Ajuda
ivaldo@ivaldo:-$ lxc exec vitoria bash
root@vitoria:-# cat /etc/ssh/sshd_config | grep PasswordAuthentication
PasswordAuthentication yes
PasswordAuthentication no
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication, then enable this but set PasswordAuthentication
root@vitoria:-#
3. SERVIÇOS HTTP/HTTPS
O que fizemos:
- Instalamos o Apache: apt install apache2
- Criamos dois sites:
- Configuramos SSL com certificado próprio
- Redirecionamos HTTP para HTTPS automaticamente
Comandos usados:
# Instalação do Apache
apt install apache2 -y
# Criação dos diretórios dos sites
mkdir /var/www/www.ivaldo.lab/html
mkdir /var/www/docs.ivaldo.lab/html
Configurações dos sites:
Arquivo: /etc/apache2/sites-available/www.ivaldo.lab.conf
<VirtualHost *:88>
ServerName www.ivaldo.lab
ServerAlias ivaldo.lab
DocumentRoot /var/www/www.ivaldo.lab/html
# Remover o redirecionamento HTTPS por enquanto
# Redirect permanent / https://www.ivaldo.lab/
</VirtualHost>
Arquivo: /etc/apache2/sites-available/docs.ivaldo.lab.conf
<VirtualHost *:88>
ServerName docs.ivaldo.lab
DocumentRoot /var/www/docs.ivaldo.lab/html
# Remover o redirecionamento HTTPS por enquanto
# Redirect permanent / https://docs.ivaldo.lab/
</VirtualHost>
Certificados SSL:
- Certificados criados em /etc/ssl/ivaldo/
- ivaldo.lab.crt (certificado)
- ivaldo.lab.key (chave privada)
root@vitoria:~# ls -la /etc/ssl/ivaldo/
total 8
drwXr-xr-x 1 root lxd 56 Oct 30 19:08 .
drwXr-xr-x 1 root root 58 Oct 30 19:03 ...
-rw-r--r-- 1 root lxd 1338 Oct 30 19:08 ivaldo.lab.crt
-rw--- 1 root lxd 1704 Oct 30 19:08 ivaldo.lab.key
root@vitoria:~#
Estrutura de diretórios:
ls -la /var/www/
root@vitoria:~# ls -la /var/www/
total 0
drwXr-xr-x 1 www-data www-data 128 Oct 30 18:09 .
drwXr-xr-x 1 root root 104 Oct 30 17:54 ...
drwXr-xr-x 1 root lxd 32 Oct 30 18:09 docs.ivaldo.lab
drwXr-xr-x 1 www-data www-data 8 Oct 30 14:57 docs.vitoria.lab
drwXr-xr-x 1 www-data www-data 20 Oct 30 14:57 html
drwXr-xr-x 1 root lxd 8 Oct 30 18:09 www.ivaldo.lab
drwXr-xr-x 1 www-data www-data 8 Oct 30 14:57 www.vitoria.lab
root@vitoria:~#
Status do Apache:
systemctl status apache2
root@vitoria:~# systemctl status apache2
apache2.service - The Apache HTTP Server
Loaded: loaded /lib/systemd/system/apache2.service; enabled; preset: enabled)
Drop-In: /run/systemd/system/service.d
--zzz-lxc-service.conf
Active: active (running) since Thu 2025-10-30 18:33:51 UTC; 42min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 3199 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Process: 3373 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 3203 (apache2)
Tasks: 55 (limit: 4603)
Memory: 7.2M
CPU: 374ms
Group: /system.slice/apache2.service
--3203 /usr/sbin/apache2 - k start
--3377 /usr/sbin/apache2 - k start
--3378 /usr/sbin/apache2 - k start
Oct 30 18:33:51 vitoria.lab systemd[1]: Started apache2.service - The Apache HTTP Server.
Oct 30 19:05:37 vitoria.lab systemd[1]: Reloading apache2.service - The Apache HTTP Server...
Oct 30 19:05:37 vitoria.lab apachectl[3366]: AMB0526: Syntax error on line 6 of /etc/apache2/sites-enabled/docs.ivaldo.lab-ssl.conf;
Oct 30 19:05:37 vitoria.lab apachectl[3366]: SickertificateFile: file '/etc/ssl/ivaldo/ivaldo.lab.crt' does not exist or is empty
Oct 30 19:05:37 vitoria.lab apachectl[3366]: Action 'graceful' failed.
Oct 30 19:05:37 vitoria.lab apachectl[3366]: The Apache error log may have more information.
Oct 30 19:05:37 vitoria.lab systemd[1]: apache2.service: Control process exited, code=exited, status=1/FALURE
Oct 30 19:05:37 vitoria.lab systemd[1]: Reload failed for apache2.service - The Apache HTTP Server...
Oct 30 19:08:41 vitoria.lab systemd[1]: Reloading apache2.service - The Apache HTTP Server...
Oct 30 19:08:41 vitoria.lab systemd[1]: Reloaded apache2.service - The Apache HTTP Server.
root@vitoria:~#
Para conseguir acessar o site dentro do container, precisei editar o arquivo hosts da máquina real:
sudo nano /etc/hosts
Adicionar a seguinte entrada:
10.176.19.158 docs.ivaldo.lab www.ivaldo.lab
Sites funcionando:
www/docs.ivaldo.lab
4. SERVIÇO PROXY (SQUID)
O que fizemos:
- Instalamos o Squid: apt install squid
- Configuramos 4 tipos de ACL:
- Rede: 10.176.19.0/24 (IP de origem)
- Horário: Segunda a Sexta, 09:00-17:00
- Domínios: .debian.org e .ubuntu.com
- Método: CONNECT (bloqueado)
- Política padrão: Negar tudo, liberar apenas o necessário
- Proxy funcionando na porta 3128
Comandos usados:
# Instalação e configuração do Squid
apt install squid -y
systemctl enable squid
systemctl start squid
Política Padrão Prudente:
http_access deny all # Nega tudo por padrão
4 ACLs Implementadas:
# Rede IP de origem
acl minha_rede src 10.176.19.0/24
# Horário
acl horario_util time MTWHF 09:00-17:00
# Domínios
acl sites_educacionais dstdomain .debian.org .ubuntu.com
# Método HTTP
acl metodos_restritos method CONNECT
Regras de Acesso:
http_access allow localhost
http_access allow minha_rede horario_util sites_educacionais
http_access deny metodos_restritos
http_access allow minha_rede
http_access deny all
Status do Squid:
systemctl status squid
Status: Active: active (running)
Teste Prático:
- Proxy funcionando e acessando www.debian.org
- Configurações de ACL aplicadas corretamente
root@vitoria:~# echo "=== ACLs IMPLEMENTADAS ==="
grep -E "~acl (minha_rede|horario_util|sites_educacionais|metodos_restritos)" /etc/squid/squid.conf
=== ACLs IMPLEMENTADAS ===
acl minha_rede src 10.17C-19.0/24
acl horario_util time MTMHF 09:00-17:00
acl sites_educacionais dstdomain .debian.org .ubuntu.com
acl metodos_restritos method CONNECT
root@vitoria:~# echo "=== REGRAS DE ACESSO ==="
grep -E "~http access (allow|deny)" /etc/squid/squid.conf | grep -v "#" | tail -6
=== REGRAS DE ACESSO ===
http_access allow localhost
http_access allow minha_rede horario_util sites_educacionais
http_access deny metodos_restritos
http_access allow minha_rede
http_access deny all
root@vitoria:~# echo "=== POLITICA PADRÃO PRUDENTE ==="
echo "http access deny all -- Nega tudo por padrão"
=== POLITICA PADRÃO PRUDENTE ===
http_access deny all -- Nega tudo por padrão
root@vitoria:~# echo "=== TESTE DO PROXY FUNCIONANDO ==="
curl --proxy http://localhost:3128 -s http://www.debian.org | head -2
=== TESTE DO PROXY FUNCIONANDO ===
root@vitoria:~# echo "=== STATUS DO SERVIÇO ==="
systemctl status squid | grep "Active:"
=== STATUS DO SERVIÇO ===
Active: active (running) since Thu 2025-10-30 20:28:16 UTC; 18h ago
root@vitoria:~#
Status do Squid:
systemctl status squid
root@vitoria:~# systemctl status squid
● squid.service - Squid Web Proxy Server
Loaded: loaded //lib/systemd/system/squid.service; enabled; preset: enabled)
Drop-In: //un/systemd/system/service.d
L-zzz-lvc-service.conf
Active: active (running) since Thu 2025-10-30 17:42:37 UTC; 1h 33min ago
Docs: man:squid(8)
Main PID: 236 (squid)
Tasks: 4 (limit: 4003)
Memory: 38.4M
CPU: 1.470s
Group: /system.slice/squid.service
├── 236 /usr/sbin/squid --foreground -sYC
├── 238 "[squid-1]" --kid squid-1 --foreground -sYC
├── 239 "[unlinkd]"
├── 3305 "[ginger]"
Oct 30 18:59:49 vitoria.lab squid[238]: Adaptation support is off.
Oct 30 18:59:49 vitoria.lab squid[238]: Store logging disabled
Oct 30 18:59:49 vitoria.lab squid[238]: DNS Socket created at [::], FD 9
Oct 30 18:59:49 vitoria.lab squid[238]: DNS Socket created at 0.0.0.0, FD 10
Oct 30 18:59:49 vitoria.lab squid[238]: Adding nameserver 127.0.0.0.53 from /etc/resolv.conf
Oct 30 18:59:49 vitoria.lab squid[238]: Adding domain lxd from /etc/resolv.conf
Oct 30 18:59:49 vitoria.lab squid[238]: HTTP Disabled.
Oct 30 18:59:49 vitoria.lab squid[238]: Pinger socket opened on FD 15
Oct 30 18:59:49 vitoria.lab squid[238]: Finished loading MIME types and icons.
Oct 30 18:59:49 vitoria.lab squid[238]: Accepting HTTP Socket connections at comMS local=[::]:3128 remote=[::] FD 12 flags=9
root@vitoria:~#
RESUMO FINAL
Todos os serviços foram implementados com sucesso:
- ✓ SSH na porta 22
- ✓ Sites www.ivaldo.lab e docs.ivaldo.lab com HTTPS
- ✓ Proxy Squid com 4 ACLs na porta 3128
- ✓ Documentação completa publicada
Documentação elaborada por: Ivaldo Fernandes de Sousa
Data de conclusão: 31/10/2025