Note:
- when
useris being used, it refers to your username pkgrefers to package(s)
Setup sudo
- Switch the user to root
su -(the param-will login to root by default) - Check for any update / upgrades (shouldn’t be any):
apt update&apt upgrade - Install the following packages
apt install openssh-server ufw libpam-pwquality sudo(vim)- SSH (
openssh-server) - Uncomplicated firewall (
ufw) - Password quality checker (
libpam-pwquality) - SuDo (
sudo) - Optionally vim (
vim)
- SSH (
- You can change the default editor to vim
sudo update-alternatives --config editor - Add yourself in the sudo group
usermod -aG sudo user-aadd the user to the group(s). Use only with the -G option.-Glist of groups to add to the user (separate groups with commas, not whitespaces)
- Check the group has been set with
groups userorgetent group sudo - Open the sudoers file with
visudo - Create this line right under the root version of it
user ALL=(ALL:ALL) ALL - You should now have access to
sudo - Exit the previous
su -by typingexitor pressingCTRL+D - Now try your sudo privileges with
sudo echo lol
Install SSH and setup
- Go to
/etc/ssh/sshd_config - Change
#Port 22toPort 4242 - Enable ufw:
ufw enable - Allow the port 4242
ufw allow 4242 - Check it
ufw status (numbered) - Restart ssh and check its status and port
service sshd restart&service sshd status - Portforward 4242 on the VM:
- Open the VM settings
- Go to
Network - Click on
Advanced - Click on
Port Forwarding - Create a new rule
- Set the
Host PortandGuest Portto4242
- Try to connect on a terminal outside the VM with
ssh [email protected] -p 4242
Password setup
Password quality check
You need the libpam-pwquality package
Enter the password quality config file sudoedit /etc/pam.d/common-password and add the following at the end of the line requisite pam_pwquality.so
difok=7number of character changes in the new password that differentiate it from the old passwordminlen=10minimum acceptable size for the new password (plus one if credits are not disabled which is the default)dcredit=-1credit for having at least one digits in the new passworducredit=-1credit for having at least one upper case in the new passwordlcredit=-1credit for having at least one lower case in the new passwordmaxrepeat=3reject passwords which contain more than 3 same consecutive charactersreject_usernamereject password if it contains the username in straight or reversed formenforce_for_rootapply those rules to root too Should get something likedifok=7 minlen=10 dcredit=-1 ucredit=-1 lcredit=-1 maxrepeat=3 reject_username enforce_for_root
Password expiration
- Go into the password expiration config file
sudoedit /etc/login.defs - Set the old values to:
PASS_MAX_DAYS 30PASS_MIN_DAYS 2PASS_WARN_AGE 7
- Change those values on your current user and root
At the end of this, you should reboot to ensure that everything is up to date with your config files
Group and user setup
user42 group
- Create a new group
sudo groupadd user42 - Add the
user42tousersudo usermod -aG user42 user - Check your groups with
groupsorgroups user
user setup
- Create a new user
sudo useradd -m test(-mcreates the home directory) - Add it to the group
sudo usermod -aG user42 test - Add a password to the user
sudo passwd test - Check if the password rules apply
sudo chage -l test - Connect to the account by disconnecting the SSH and reconnecting
Strong config for sudo
- Go to the sudo config
sudo visudo - sudo is limited to 3 authentications attempts by default
- To set up the custom error message add a line following the
DefaultsDefaults badpass_message="the custom msg goes here"if you fail to enter the correct password you will get your custom error message - If the sudo folder does not exist, create it
mkdir /var/log/sudo - To log both inputs and outputs to
/var/log/sudo/sudo.loguseDefaults log_input, log_output, logfile="/var/log/sudo/sudo.log" - Enabling the TTY mode will prevent non login session (cron, shell, perl, python, bin scripts etc.) to run sudo
Defaults requiretty - Set the paths that can be used by
sudoDefaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"