Oracle Linux Basic Administration Series - Part 11 - How to Configure and Secure SSH Access in Oracle Linux
- Jason Beattie
- 19 hours ago
- 4 min read
Introduction
SSH is the most common method to access and manage Linux servers remotely.It allows encrypted communication between your local system and the Oracle Linux server, making it both powerful and secure - if configured correctly.
In this blog, you’ll learn how to:
Install and enable SSH
Configure key-based authentication
Restrict and secure SSH access
Troubleshoot and verify SSH connections
Step 1: Check and Install the SSH Service
SSH usually comes preinstalled, but if not, install it:
sudo dnf install -y openssh-serverEnable and start the SSH service:
sudo systemctl enable --now sshdCheck status:
sudo systemctl status sshd
Step 2: Connect to Your Server via SSH
From another machine (Linux, macOS, or Windows PowerShell):
ssh username@server_ipExample:
ssh admin@192.168.1.100The first time you connect, you’ll be asked to accept the server’s fingerprint:
Are you sure you want to continue connecting (yes/no)? yesStep 3: Set Up SSH Key-Based Authentication
Password authentication is convenient but less secure.A stronger alternative is public/private key authentication.
On your local machine:
Generate an SSH key pair:
ssh-keygen -t rsa -b 4096
Copy the public key to the server:
ssh-copy-id username@server_ipOr manually copy it:
cat ~/.ssh/id_rsa.pub | ssh username@server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"Now test the connection — you should log in without a password:
ssh username@server_ipStep 4: Secure SSH Configuration
The main SSH config file is:
/etc/ssh/sshd_configOpen it for editing:
sudo vi /etc/ssh/sshd_configRecommended security settings:
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#In FIPS mode Ed25519 keys are not supported, please comment out the next line
HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# This system is following system-wide crypto policy. The changes to
# crypto properties (Ciphers, MACs, ...) will not have any effect here.
# They will be overridden by command-line options passed to the server
# on command line.
# Please, check manual pages for update-crypto-policies(8) and sshd_config(5).
# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication no
# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes
# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
# WARNING: 'UsePAM no' may cause several problems.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
# It is recommended to use pam_motd in /etc/pam.d/sshd instead of PrintMotd,
# as it is more configurable and versatile than the built-in version.
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs serversudo systemctl restart sshd🚨 Step 5: Allow SSH Through the Firewall
If your firewall is enabled, you must open the SSH port.
For the default port (22):
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
If you changed the port (e.g., 2222):
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload🧠 Step 6: Verify SSH Configuration
To test syntax before restarting the service:
sudo sshd -tIf nothing is returned, your configuration is valid.
Step 7: Troubleshooting SSH
If SSH fails:
Check that the service is running:
sudo systemctl status sshd
Verify the firewall allows your SSH port:
sudo firewall-cmd --list-all
Review SSH logs:
sudo journalctl -u sshd -xe
Conclusion
You’ve now learned how to set up and secure SSH access on Oracle Linux.SSH is your primary gateway into a remote server, keeping it secure ensures your entire system stays protected.
In the next post, we’ll move on to configuring the firewall using firewalld, another essential component of server security.



Comments