# AlmaLinux 9
dnf update
# Ubuntu 22.04
apt update# Asia/Riyadh
# Africa/Cairo
timedatectl set-timezone 'Asia/Kuwait'date
# Mon Aug 1 12:08:29 +03 2022hostnamectl set-hostname my-new-hostnameyou must logout and login again to see updated hostname
hostname
# my-new-hostnameyou must logout and login again to see updated hostname
vi /etc/hosts# IPv4
...
127.0.0.1 localhost.localdomain localhost
# Add following Line
100.100.100.100 my-new-hostname.example.com my-new-hostname
# IPv6
2600:3c01::a123:b456:c789:d012 my-new-hostname.example.com my-new-hostnameCreate the user, replacing example_user with your desired username
# AlmaLinux 9
useradd example_user && passwd example_user
# Ubunut 22.04
adduser example_user && passwd example_user# AlmaLinux 9
usermod -aG wheel example_user
# Ubunut 22.04
usermod -aG sudo example_user# Create the .ssh directory for example_user
mkdir -p /home/example_user/.ssh
chown example_user:example_user /home/example_user/.ssh
chmod 700 /home/example_user/.ssh
# Copy the SSH public key into authorized_keys
# Example command if you have the public key ready:
echo "your-ssh-public-key-here" >> /home/example_user/.ssh/authorized_keys
# or
nano /home/example_user/.ssh/authorized_keys
# Set the correct permissions for the authorized_keys file
chmod 600 /home/example_user/.ssh/authorized_keys
chown example_user:example_user /home/example_user/.ssh/authorized_keysexitsudo su
# [example_user@my-new-hostname #]- this mean the server is configred to prevent wheel group users
sudo su
# example_user is not in the sudoers file. This incident will be reported.- You must login as root user to allow your user
# After Login as root go to sudoers users
vi /etc/sudoers
# Then add the next line after root ALL=(ALL) ALL
example_user ALL=(ALL) ALL- you must login as root user
# After Login as root go to sudoers users
vi /etc/sudoers
# In AlmaLinux 97 If the wheel group is commented remove the leading '#' to allow it or add it if not found in the file
%wheel ALL=(ALL) ALL
# In ubunut 22.04 If the wheel group is commented remove the leading '#' to allow it or add it if not found in the file
%sudo ALL=(ALL:ALL) ALLNow you can administer your Compute Instance from your new user account instead of root
-
To create an ssh key please follow this article
sudo vi /etc/ssh/sshd_configSearch for PermitRootLogin under Authentication and change to no
# Authentication:
...
# Default is PermitRootLogin yes
PermitRootLogin no-
- Search for
PasswordAuthenticationin the file and if not found or it was commented please add or uncomment it by removing leading#then change tono - Search for
PubkeyAuthenticationin the file and if not found or it was commented please add or uncomment it by removing leading#then change toyes
- Search for
PubkeyAuthentication yes
# Default is PasswordAuthentication yes
PasswordAuthentication no- The SSH daemon listens for incoming connections over both IPv4 and IPv6 by default, if you need both protocols leave this step if not please disable what you don't need
This does not disable the protocol system-wide, it is only for the SSH daemon
Search for AddressFamily in the file and if not found or it was commented please add or uncomment it by removing leading # then change to inet for IPv4 or inet6 for IPv6
...
# Port 22
# Default is AddressFamily any
AddressFamily inet# AlmaLinux 9
sudo systemctl restart sshd
# Ubuntu 22.04
sudo systemctl restart ssh