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

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


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


# generate md5 hash from password
# generate md5 hash from password

Version du 24 février 2021 à 15:33

Liens

Commandes

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

# reboot
reboot

# shutdown
poweroff

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

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

Upgrade PHP to 7.4

Bash.svg
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/apache2
# sudo add-apt-repository ppa:ondrej/nginx-mainline

sudo apt update && sudo apt upgrade

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

Upgrade version

Bash.svg
sudo apt-get install software-properties-common

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
# pub   rsa4096 2016-03-30 [SC]
#       177F 4010 FE56 CA33 3630  0305 F165 6F24 C74C D1D8
# uid           [ unknown] MariaDB Signing Key <signing-key@mariadb.org>
# sub   rsa4096 2016-03-30 [E]

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://ftp.igh.cnrs.fr/pub/mariadb/repo/10.5/ubuntu bionic main'
# deb [arch=arm64,amd64,ppc64el] https://ftp.igh.cnrs.fr/pub/mariadb/repo/10.5/ubuntu bionic main
# # deb-src [arch=arm64,amd64,ppc64el] https://ftp.igh.cnrs.fr/pub/mariadb/repo/10.5/ubuntu bionic main

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
# runtime
wget https://download.visualstudio.microsoft.com/download/.../aspnetcore-runtime-x-linux-arm64.tar.gz
tar xzf aspnetcore-runtime-x-linux-arm64.tar.gz -C dotnet

sudo mv dotnet /usr/share

export DOTNET_ROOT=/usr/share/dotnet
export PATH=$PATH:/usr/share/dotnet

# test
dotnet --info

# sdk
wget https://download.visualstudio.microsoft.com/download/.../dotnet-sdk-x-linux-arm64.tar.gz
tar xzf dotnet-sdk-x-linux-arm64.tar.gz
~/.zshenv
# .NET Core
export DOTNET_ROOT="/usr/share/dotnet"
export PATH=$PATH:"/usr/share/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.

Gitweb

Bash.svg
sudo apt install gitweb
# /etc/apache2/conf-available/gitweb.conf
# /etc/gitweb.conf
# /usr/lib/cgi-bin/gitweb.cgi -> ../../share/gitweb/gitweb.cgi (installed by git)

# enable cgid module if not already done
sudo apachectl -M | grep cgi
# cgid_module (shared)
sudo a2enmod cgid

Use gitolite repositories

/etc/gitweb.conf
$projectroot = "/var/lib/gitolite3/repositories";
Bash.svg
# only user gitolite3 can access to /var/lib/gitolite3/repositories
# and gitweb runs under the www-data user
# here is a way to give access at user www-data to /var/lib/gitolite3/repositories
sudo setfacl -RPm u:www-data:rX /var/lib/gitolite3/repositories

Gitolite

Bash.svg
# before install copy your local ssh public key to the server (~/.ssh/id_rsa.pub → /tmp/<user>.pub)
sudo apt install gitolite3
# during installation a ssh public key is asked to allow the administrator to login, select the ssh public key you copied to the server
# installation creates the user gitolite3 and its home directory /var/lib/gitolite3

# test if it worked
ssh gitolite3@<server> info
# hello admin, this is gitolite3@<server> running gitolite3 3.6.7-2 (Debian) on git 2.17.1

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

# create a new repo
# clone gitolite-admin repo, edit gitolite.conf to add the repo, commit the change
# add the newly created remote repository to your already existing local git repo
git remote add origin gitolite3@<server>:<project>
# push and set the remote as upstream
git push --set-upstream origin master
conf/gitolite.conf
# add new repo
repo new_repo
    RW+     =   @all
Commit and push to apply changes.

GitLab

Not supported on ARM architecture
Bash.svg
# install and configure the necessary dependencies 
sudo apt install curl openssh-server ca-certificates postfix

# add the GitLab package repository (package source /etc/apt/sources.list.d/ and GPG keys)
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

# installation
sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ce

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