Ubuntu server 18.04

De Banane Atomic
Révision datée du 10 août 2019 à 09:06 par Nicolas (discussion | contributions) (→‎Installation)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à la navigationAller à la recherche

Liens

Commandes

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

# reboot
reboot

# shutdown
poweroff

.Net Core

Bash.svg
# register the Microsoft key, register the product repository, and install required dependencies
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-2.1
# installe les dépendances suivantes (plus à jour)
# aspnetcore-store-2.0.0 aspnetcore-store-2.0.3 aspnetcore-store-2.0.5 aspnetcore-store-2.0.6 aspnetcore-store-2.0.7 aspnetcore-store-2.0.8
# dotnet-host dotnet-hostfxr-2.0.7 dotnet-runtime-2.0.7 dotnet-runtime-deps-2.1.0-rc1 dotnet-sdk-2.1.200
# liblttng-ust-ctl4 liblttng-ust0 liburcu6

Nginx

Bash.svg
# installation
sudo apt install nginx

# serveur nginx
systemctl status nginx
# recharger la configuration sans dropper les connexions
sudo systemctl reload nginx

Nginx et .Net Core

Bash.svg
# activer le fichier de configuration
sudo ln -s /etc/nginx/sites-available/mydotnetcoresite.conf /etc/nginx/sites-enabled/mydotnetcoresite.conf
/etc/nginx/sites-available/mydotnetcoresite.conf
server {
    listen        80;
    server_name   webappcore.local;
    location / {
        proxy_pass         http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $http_host;
        proxy_cache_bypass $http_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-get install mariadb-server
# définit le mot de passe root et configure mysql
sudo mysql_secure_installation
# connexion avec root après l'installation
sudo mysql

# créer un autre compte super user
create user 'mon_compte'@'localhost' identified with 'unix_socket';
grant all on *.* to 'mon_compte'@'localhost';
flush privileges;

# créer un compte system
create user 'dotnet'@'localhost' identified by 'my_password';
grant all on *.* to 'dotnet'@'localhost';
flush privileges;

# connexion avec un autre user
mysql -u <my_user> -p

systemctl status mysql
Mysql.svg
# modifier l'utilisateur root pour qu'il s'authentifie avec un mdp
alter user 'root'@'localhost' identified with 'mysql_native_password';
#alter user 'root'@'localhost' identified with mysql_native_password BY 'xxx';
flush privileges;

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Se connecter à mysql avec sudo

SSH

openssh est déjà installé et démarré.
Pour se logguer avec root:

/etc/ssh/sshd_config
PermitRootLogin yes
Bash.svg
# activer le compte root pour le terminal
sudo –i passwd root
# déverrouille le compte et définit un mot de passe

# redémarrer ssh
sudo systemctl restart sshd

netplan

/etc/netplan/50-cloud-init.yaml
network:
    version: 2
    ethernets:
        eno1:
            # DHCP
            addresses: []
            dhcp4: yes
            # IP fixe
            addresses: [192.168.0.1/24]
                gateway4: 192.168.0.254
            nameservers:
                search: [local,  home]  # DNS search domain (noms associés à l'ip locale)
                addresses: [8.8.8.8, 8.8.7.7]
            # WOL
            match:
                macaddress: xx:xx:xx:xx:xx:xx
            wakeonlan: true

            optional: true  # ne pas attendre que le réseau soit prêt lors du boot
Bash.svg
# tester la syntaxe
netplan try

netplan generate
netplan apply
# créé les fichiers /run/systemd/network/10-netplan-eno1.link et /run/systemd/network/10-netplan-eno1.network

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

WOL

can't get wake-on-lan to work with netplan config file

Bash.svg
# tester si wol est activé
# installer ethtool: apt install ethtool
# lister les interfaces: ls /sys/class/net
sudo ethtool [interface]
# Supports Wake-on: pumbg
# Wake-on: d (disabled)

Utiliser netplan pour activer wol au démarrage.

Samba

Bash.svg
# installation
sudo apt install samba
# vérifier l'installation
whereis samba
# samba: /usr/sbin/samba /usr/lib/x86_64-linux-gnu/samba /etc/samba /usr/share/samba ...

sudo systemctl restart smbd

Configurer Samba
Chemin d'accès \\host\myshare

yarn

Bash.svg
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt update && sudo apt install yarn

# erreur trying to overwrite '/usr/bin/yarn', which is also in package cmdtest 0.32-1
sudo apt remove cmdtest

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

ripgrep

Bash.svg
# installation: télécharger le fichier *.deb
sudo dpkg -i ripgrep_0.8.1_amd64.deb

Compte root

Il est désactivé et vérouillé par défaut: pas de connexion possible avec root.

Bash.svg
sudo grep root /etc/passwd
# root:x:0:0:root:/root:/bin/bash
# “x” représente un mot de passe vide. Le compte est désactivé.
sudo grep root /etc/shadow
# root:!$6$x...:17654:0:99999:7:::
# “!” représente un mot de passe verrouillé. Le compte est verrouillé.
# root:*:17647:0:99999:7:::
# “*” signifie  qu'aucun mot de passe n'a été définit.

# connexion ponctuelle au compte root
sudo -i

# activer le compte root pour le terminal
sudo -i passwd root
# déverrouille le compte et définit un mot de passe

# désactiver le compte root pour le terminal
sudo passwd -dl root
# verrouille le compte et définit un mot de passe vide

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>

Erreurs

Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

Bash.svg
sudo umount /dev/sda1 
sudo fsck /dev/sda1