Commandes shell usuelles pour première install d'une machine, etc...
Pour Linux.
To be able to connect to the PC or server, by SSH.
Ces commandes sont le minimum usuel à utiliser et appliquer, pour démarrer sur la machine en SSH.
Ces commandes sont idempotents (comme lors de l'utilisation de tasks Ansible...).
=> à utiliser sans modération... en tout cas, sans craindre d'executer une commande, si le service SSH est déjà activé, ou le port 22 déjà ouvert...
sudo dnf install openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --zone=public --permanent --add-service=ssh
firewall-cmd --reload
Ci-après, les mêmes choses, mais avec explications, variantes, et indications complémentaires.
Install SSH server.
See : "Comment installer, démarrer et se connecter à SSH Server sur Fedora Linux"
https://fr.linux-console.net/?p=11432
Vérifier si le serveur openssh est installé sur votre système Fedora.
rpm -qa | grep openssh-server
Si pas présent :
sudo dnf install openssh-server
Vérifiez l’état du serveur SSH
sudo systemctl status sshd
Enable en tant que service et/ou démarrer le serveur SSH :
sudo systemctl enable sshd
sudo systemctl start sshd
Voir le port 22 ouvert pour de nouvelles connexions entrantes
sudo ss -lt
La colonne "Local Address:Port" doit avoir une ligne marquée "ssh", pour IPv4 et peut-être une aussi pour IPv6.
See : "How to open and close ports on RHEL 8 / CentOS 8 Linux"
https://linuxconfig.org/redhat-8-open-and-close-ports
With Firewalld
Check for already opened ports or enabled systemd service
firewall-cmd --list-all
Check whether the service you are trying to configure your firewall with is available as a preconfigured feature
firewall-cmd --get-services
firewall-cmd --get-services | grep -i "ssh"
Obtain a list of zones you wish the port to be opened within:
firewall-cmd --get-zones
In most cases you are interested in the 👉public zone which is the default firewall zone
for all operations without explicitly providing zone name as an argument to the firewall-cmd command.
Open port or service.
as root
sudo firewall-cmd --zone=public --permanent --add-service=ssh
or by port number :
sudo firewall-cmd --zone=public --permanent --add-port 22/tcp
Reload firewall settings
firewall-cmd --reload
Confirm that port or service was opened successfully:
firewall-cmd --list-all
If necessary, to close the ports.
Close port or service. The below command will close the http service in the public zone:
sudo firewall-cmd --zone=public --permanent --remove-service ssh
sudo firewall-cmd --zone=public --permanent --remove-port 22
firewall-cmd --reload