« Ubuntu arm 18.04 » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 436 : Ligne 436 :


# clone the admin repository
# clone the admin repository
git clone gitolite3@<server>:gitolite-admin
git clone <user>@<server>:gitolite-admin
</kode>
</kode>



Version du 27 avril 2020 à 19:22

Liens

Commandes

Bash.svg
# mise à jour
adg
sudo apt update && sudo apt upgrade

# reboot
reboot

# shutdown
poweroff

Apache

  • Dossier de déploiement des web sites /var/www/html
  • Dossier des configurations des web sites /etc/apache2/sites-available
Bash.svg
# service apache
systemctl restart apache2
Utiliseur Apache: www-data

MySql / MariaDb

L'utilisateur root utilise par défaut l'authentification unix_socket.
Il faut donc utiliser sudo pour se connecter avec root et non pas le mdp.
Bash.svg
sudo apt install mariadb-server
# connexion avec root après l'installation
sudo mysql

# status
systemctl status mysql

phpmyadmin

Bash.svg
sudo apt install phpmyadmin
# coller dans ncurse: Shift + Insert
# login: phpmyadmin
# url: http://myserver/phpmyadmin
Mysql.svg
# accorder tous les privilèges au compte phpmyadmin
GRANT ALL ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Mediawiki

Bash.svg
wget https://releases.wikimedia.org/mediawiki/1.33/mediawiki-1.33.0.tar.gz
tar -xzf /mediawiki-*.tar.gz
sudo mv -T mediawiki-* /var/www/mediawiki
Mysql.svg
# peut-être pas nécessaire car fait lors de la configuration
CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE my_wiki;
USE my_wiki;

GRANT ALL ON my_wiki.* TO 'my_user'@'localhost';

SSH

openssh est déjà installé et démarré.

Bash.svg
# sshfs
sudo apt install sshfs

OpenVPN

CA certificate

Avec Ubuntu les serveurs CA et VPN sont sur la même machine.
~/openvpn-ca/vars
export KEY_COUNTRY="FR"
export KEY_PROVINCE="Paris"
export KEY_CITY="Paris"
export KEY_ORG="MyOrg"
export KEY_EMAIL="admin@domain.fr"
export KEY_OU="MyUnit"

# X509 Subject Field
export KEY_NAME="myservername"
Bash.svg
# copie le contenu du dossier /usr/share/easy-rsa
make-cadir ~/openvpn-ca
cd ~/openvpn-ca

# load variables
source ./vars
./clean-all

# create CA files (keys/ca.crt, keys/ca.key) 
./build-ca

Server certificate

Bash.svg
# le fichier openssl.cnf n'existe plus. Il s’appelle openssl-1.0.0.cnf. Il faut donc le lier
ln -s openssl-1.0.0.cnf openssl.cnf
# create missing .rnd file
dd if=/dev/urandom of=$HOME/.rnd bs=256 count=1

# generate a certificate and private key for the server
./build-key-server myservername
# les fichiers suivants sont créés dans le dossier keys
# 01.pem index.txt index.txt.attr myservername.crt myservername.csr myservername.key serial

# generate Diffie Hellman parameters
./build-dh
# generate an HMAC signature
openvpn --genkey --secret keys/ta.key

# copy certificates and keys
cd keys/
cp ca.crt myservername.crt myservername.key ta.key dh2048.pem /etc/openvpn/server

Client certificate

Bash.svg
# load variables
source ./vars

./build-key --pass [client-name]
# --pass: Build password-protected key
# --pkcs12: Build key in PKCS#12 format (*.p12 protected with password)
# les fichiers suivants sont créés dans le dossier keys
# 02.pem index.txt index.txt.attr client-name.crt client-name.csr client-name.key serial

# revoke certificate
./revoke-full [client-name]
Le fichier keys/index.txt contient la liste des certificats valides et révoqués.

Server configuration

Bash.svg
# copier le fichier de configuration d'exemple
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/server
sudo gzip -d /etc/openvpn/server/server.conf.gz
/etc/openvpn/server/server.conf
ca ca.crt
cert [server-name].crt
key [server-name].key
dh dh2048.pem
tls-auth ta.key 0
Bash.svg
# start openvpn with server-name configuration
sc-start openvpn-server@[server-name]

IP forward

/etc/sysctl.conf
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
Bash.svg
# reload sysctl
sudo sysctl -p /etc/sysctl.conf
# restart the procps service
sudo /etc/init.d/procps restart

Firewall

Bash.svg
sudo ufw allow 1194/udp comment 'OpenVPN udp port 1194'
/etc/default/ufw
DEFAULT_FORWARD_POLICY="ACCEPT"
/etc/ufw/before.rules
#   ufw-before-forward
#

# START OPENVPN RULES
# NAT table rules
*nat
:POSTROUTING ACCEPT [0:0]
# Allow traffic from OpenVPN client to eth0
-A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
COMMIT
# END OPENVPN RULES

# Don't delete these required lines, otherwise there will be errors
*filter

zsh - oh my zsh

Bash.svg
apt install zsh zsh-syntax-highlighting
# zsh install zsh-common

# install oh-my-zsh et change de shell
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
~/.zshrc
# plugins
plugins=(common-aliases debian extract git sudo systemd wd)

# don't store in history commands prefixed with a space (test with: history | tail)
setopt HIST_IGNORE_SPACE

# zsh-syntax-highlighting, doit être sourcé en dernier
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

Network Manager

Bash.svg
# vérifier que le packet est installé
dpkg -l "network-manager"

# vérifier que le service fonctionne
sc-status NetworkManager

# lister les connections
nmcli c show
# afficher les détails d'une connection
nmcli c show <NAME>

netplan

/etc/netplan/01-netcfg.yaml
network:
    version: 2
    renderer: NetworkManager
    ethernets:
        eth0:
            addresses: [192.168.0.x/24]
            gateway4: 192.168.0.y
            nameservers:
                addresses: [192.168.0.x, 192.168.0.y]
Renderers: NetworkManager networkd
Bash.svg
# tester la syntaxe (possibilité de revert)
sudo netplan try

sudo netplan generate
sudo netplan apply
# --debug if you run into some issues
# créé le fichier /run/systemd/network/10-netplan-eth0.network

# vérifier la configuration en cour
netplan ip leases [interface]

Glances

Service web équivalent à top. Service accessible via host:61208

Bash.svg
apt install glances

# démarrer le service web
glances -w

Reverse proxy to the Glances Web UI

/etc/apache2/sites-available/000-default.conf
# redirect host:80/glances to host:61208
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https?://[^/]+/glances
RewriteCond %{REQUEST_URI} !^/glances
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^/(.*) /glances/$1 [QSA,R]
ProxyPass /glances/ http://localhost:61208/
ProxyPassReverse /glances/ http://localhost:61208/
Redirect permanent /glances http://n2/glances/

Start Glances through Systemd

/etc/systemd/system/glances-web-ui.service
[Unit]
Description=Glances Web UI
After=network.target

[Service]
ExecStart=/usr/bin/glances -w
Restart=on-abort

[Install]
WantedBy=multi-user.target

Torrent

Bash.svg
sudo apt install transmission-daemon
# transmission-cli transmission-common

sc-status transmission-daemon
/etc/transmission-daemon/settings.json
{
    "rpc-port": 9091,
    "rpc-whitelist": "127.0.0.1,192.168.x.x",
    "peer-port": 51413,
}

Amule

Bash.svg
sudo apt install amule-daemon

sc-status amule-daemon

# create an amule user
useradd -r -d /var/lib/amule-daemon -s /usr/sbin/nologin amule

# generate md5 hash from password
echo -n password | md5sum | cut -d ' ' -f1
/etc/default/amule-daemon
# The init.d script will only run if this variable non-empty.
AMULED_USER="amule"

# You can set this variable to make the daemon use an alternative HOME.
# The daemon will use $AMULED_HOME/.aMule as the directory, so if you
# want to have $AMULED_HOME the real root (with an Incoming and Temp
# directories), you can do `ln -s . $AMULED_HOME/.aMule`.
AMULED_HOME="/var/lib/amule-daemon"
/var/lib/amule-daemon/.aMule/amule.conf
Port=4662
UDPPort=4672
TempDir=/var/lib/amule-daemon/.aMule/Temp
IncomingDir=/var/lib/amule-daemon/.aMule/Incoming

[ExternalConnect]
ECPort=4712
ECPassword=ef7628c92bff39c0b3532d36a617cf09

.NET Core

ARM64 support requires Linux kernel 4.14 or higher.

Installation

Bash.svg
mkdir ~/dotnet
cd ~/dotnet

wget https://download.visualstudio.microsoft.com/download/.../dotnet-sdk-x-linux-arm64.tar.gz
wget https://download.visualstudio.microsoft.com/download/.../aspnetcore-runtime-x-linux-arm64.tar.gz

tar xzf dotnet-sdk-x-linux-arm64.tar.gz
tar xzf aspnetcore-runtime-x-linux-arm64.tar.gz

export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet

# test
dotnet --info
~/.zshenv
# .NET Core
export DOTNET_ROOT="$HOME/dotnet"
export PATH=$PATH:"$HOME/dotnet"

Console

Bash.svg
# create the project
dotnet new console -o dotnet-console

# build the project
cd dotnet-console
dotnet build

# run the binary
bin/Debug/netcoreapp3.1/dotnet-console

ASP.NET Core with React.js and Redux

Bash.svg
# create the project
dotnet new reactredux -o dotnet-reactredux

# install node.js and npm
sudo apt install nodejs npm

# build the project
cd dotnet-reactredux
dotnet build

# start the server
dotnet run

Blazor

SQL Server 2019

SQL Server is not supported on ARM architecture.

gitolite

Bash.svg
sudo apt install gitolite3
# during installation a ssh public key is asked to allow the administrator to login, select your shh public key
/home/<user>/.ssh/id_rsa.pub

# installation creates the user gitolite3 and its home directory /var/lib/gitolite3
# /var/lib/gitolite3/repositories/
# /var/lib/gitolite3/.ssh

# clone the admin repository
git clone <user>@<server>:gitolite-admin

Astuces

Bash.svg
# cp is by default an alias to cp -i
# to use cp only:
\cp

# get OS version, kernel version, architecture, hostname
hostnamectl

Installation

Bash.svg
# ajouter un compte (-m: create the user's home directory)
sudo useradd -m -G users,sudo <username>

# changer le mot de passe d'un autre compte
sudo passwd <username>

# afficher la configuration courante (se reloguer pour voir les changements)
locale
# liste les locales disponibles
locale -a
# ajouter une locale (modifie le fichier /etc/locale.gen)
sudo locale-gen fr_CH.UTF-8
# définir une LANG (modifie la fichier /etc/default/locale)
update-locale LANG=fr_CH.UTF-8

# get current time zone
timedatectl status
# list all available time zone
timedatectl list-timezones
# set a timezone
sudo timedatectl set-timezone Europe/Paris