You can disable and remove the OpenSSH server and its configuration using the following commands.
Remove OpenSSH server and ssh client from Linux
Make sure you type commands as per your Linux distro.
Linux: RHEL / CentOS / Fedora / Red Hat / Scientific Linux Delete SSH Server
Type the following commands as the root user (you must login using either server console or remote login using KVM over IP/IPMI):
# chkconfig sshd off
# service sshd stop
# yum erase openssh-server
You need to edit and update firewall rules that allows inbound connections to SSHs tcp port # 22. Edit /etc/sysconfig/iptables and /etc/sysconfig/ip6tables. In each file find and delete the line that access connection to port # 22. A sample entry:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
Save and close the file. Restart the Linux firewall:
# service iptables restart
# service ip6tables restart
RHEL / CentOS Linux 7 and 8 remove ssh server
Run the following command
sudo yum remove openssh-server
Again update your CentOS 7/8 firewall rules:
sudo firewall-cmd --remove-service=ssh --permanent
sudo firewall-cmd --reload
See How to set up a firewall using FirewallD on RHEL 8 for more info.
Debian / Ubuntu Linux Remove SSHD Server
Type the following commands:
# apt-get --purge remove openssh-server
Again, you need to edit and update firewall rules or firewall shell scripts that allows inbound connections to SSHs tcp port # 22.
FreeBSD Unix Disable OpenSSHD Server
Freebsd and may other Unix like operting system install OpenSSH server as part of base system. In other words you simply can not delete binary package. First, stop sshd service, enter:
# /etc/rc.d/sshd stop
To disable openssh, edit /etc/rc.conf file and located the following line:
sshd_enable="YES"
To disable sshd, enter:
sshd_enable="NO"
You can rebuild your FreeBSD base system without OpenSSH. You need to edit /etc/src.conf and set WITHOUT_OPENSSH to yes:
WITHOUT_OPENSSH=yes
See Freebsd handbook and src.conf man page for more information.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 1 comment... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Have a question or comment? Post it on the forum thread here.