Bonjour,
Je ne sais pas si cela va intéresser grand monde mais bon je me lance.
Si comme moi en ssh vous aimez bien avoir quelques couleurs et surtout un écran accueil après login afin d’être sûr d’être sur la bonne machine quand vous vous loguez, c’est pour vous
Pour vous donner une idée voilà à quoi cela ressemble
Avoir des couleurs en SSH
1/ Se connecter en ssh et passer en root, sudo -i
2/ Editer le fichier ~/.bashrc, exemple avec nano sudo nano ~/.bashrc
Vous devriez avoir ceci :
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
Il suffit de décommenter les lignes qui sont en couleurs ci dessus et la couleur sera à vous dans bash.
Accueil personnalisé motd
Toujours en étant connecté en SSH et en étant root bien sûr
1/ On va installer le paquet qui permet d’écrire le nom du système apt-get update && apt-get install figlet
2/ Aller dans /etc : cd /etc
3/ Ou vous avez un dossier update-motd.d
et vous allez dedans : cd update-motd.d
3b/ Ou vous ne l’avez pas et on va le créer : mkdir /update-motd.d && chmod 644 /update-motd.d
4/ Si vous l’avez créé aller dedans, si il était présent, supprimer le fichier qui s’y trouve : rm 10-uname
A partir de là nous allons créer des fichiers pour définir la bannière que j’ai montré en haut. Le nom des fichiers est important, donc 00-xxx 10-xxx 20-xxx etc.
Donc vous êtes dans /etc/update-motd.d
5/ Création du fichier colors : nano colors
Voici le code à copier pour colors
NONE="\033[m"
WHITE="\033[1;37m"
GREEN="\033[1;32m"
RED="\033[0;32;31m"
YELLOW="\033[1;33m"
BLUE="\033[34m"
CYAN="\033[36m"
LIGHT_GREEN="\033[1;32m"
LIGHT_RED="\033[1;31m"
Dans nano : CTRL + O pour écrire, Entrée pour valider et CTRL + X pour quitter
6/ Création du fichier hostname : nano 00-hostname
Voici le code à copier pour 00-hostname
#!/bin/sh
. /etc/update-motd.d/colors
printf "\n"$LIGHT_RED
figlet " "$(hostname -s)
printf $NONE
printf "\n"
7/ Création du fichier avec la bannière information : nano 10-banner
Voici le code à copier pour 10-banner
#!/bin/bash
#
# Copyright (C) 2009-2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
. /etc/update-motd.d/colors
[ -r /etc/update-motd.d/lsb-release ] && . /etc/update-motd.d/lsb-release
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
# Fall back to using the very slow lsb_release utility
DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
re='(.*\()(.*)(\).*)'
if [[ $DISTRIB_DESCRIPTION =~ $re ]]; then
DISTRIB_DESCRIPTION=$(printf "%s%s%s%s%s" "${BASH_REMATCH[1]}" "${YELLOW}" "${BASH_REMATCH[2]}" "${NONE}" "${BASH_REMATCH[3]}")
fi
echo -e " "$DISTRIB_DESCRIPTION "(kernel "$(uname -r)")\n"
# Update the information for next time
printf "DISTRIB_DESCRIPTION=\"%s\"" "$(lsb_release -s -d)" > /etc/update-motd.d/lsb-release &
8/ Création du dernier fichier, les infos systèmes : nano 20-sysinfo
Voici le code à copier pour 20-sysinfo
#!/bin/bash
proc=`(echo $(more /proc/cpuinfo | grep processor | wc -l ) "x" $(more /proc/cpuinfo | grep 'model name' | uniq |awk -F":" '{print $2}') )`
memfree=`cat /proc/meminfo | grep MemFree | awk {'print $2'}`
memtotal=`cat /proc/meminfo | grep MemTotal | awk {'print $2'}`
uptime=`uptime -p`
addrip=`hostname -I | cut -d " " -f1`
# Récupérer le loadavg
read one five fifteen rest < /proc/loadavg
# Affichage des variables
printf " Processeur : $proc"
printf "\n"
printf " Charge CPU : $one (1min) / $five (5min) / $fifteen (15min)"
printf "\n"
printf " Adresse IP : $addrip"
printf "\n"
printf " RAM : $(($memfree/1024))MB libres / $(($memtotal/1024))MB"
printf "\n"
printf " Uptime : $uptime"
printf "\n"
printf "\n"
9/ On a bientôt fini il faut à présent rendre ces fichiers exécutables donc il faut passer ces commandes :
chmod 755 00-hostname
chmod 755 10-banner
chmod 755 20-sysinfo
10/ Maintenant on va remplacer l’ancien motd par le notre
rm /etc/motd
ln -s /var/run/motd /etc/motd
Voilà au prochain login vous aurez votre motd à vous dont bien sûr vous pouvez changer la couleur du nom du système dans le fichier ou ajouter dans sysinfo une ligne avec l’adresse http ou autre de votre serveur