Created
May 19, 2022 22:41
-
-
Save xholicka/6c3c95f701437b87a5af43666eda3563 to your computer and use it in GitHub Desktop.
YT - 2 - Static IP & SSH keys & Firewall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ip address | |
hostname -I | |
# you can use "nano" or your other favorite texteditor, my favourite is "vim" | |
sudo vim /etc/dhcpcd.conf | |
sudo apt install vim | |
sudo vim /etc/dhcpcd.conf | |
interface wlan0 | |
static ip_address=10.0.0.101/24 | |
static routers=10.0.0.138 | |
static domain_name_server=10.0.0.138 8.8.8.8 | |
:wq | |
sudo reboot | |
sudo apt update | |
sudo apt full-upgrade | |
sudo apt autoclean | |
sudo apt autoremove (full-upgrade removes older packages) | |
clear | |
passwd | |
# ok now we need to generate ssh key pairs (public and private) | |
# and save them somewhere safe on our computer | |
putty key generator # on windows | |
#dont forget to copy that key thats going to "authorized_keys" on server | |
ssh-keygen -t rsa # on macos and linux (keys saved in /home/youruser/.ssh/) | |
# copy public key to server on linux | |
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] | |
# copy public key to server on macos - if you dont know or use homebrew (or brew) on macos I strongly recommend it | |
brew install ssh-copy-id | |
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] | |
install -d -m 700 ~/.ssh | |
vim .ssh/authorized_keys | |
# paste the public key here | |
# now we need to disable logging in with password | |
sudo vim /etc/ssh/sshd_config | |
# look for or search for PasswordAuthentication and set it to NO | |
PasswordAuthentication no | |
:wq | |
# i like to do reboot at this time to check if everything is ok after reboot | |
sudo reboot | |
# add user to ssh login and point to private key - little tip here - save the configuration in putty so you dont need to set it everytime you try to connect | |
# ufw firewall | |
sudo apt install ufw | |
clear | |
sudo ufw limit 22/tcp # make sure to add this so you don't lock yourself out of your raspberry (presumably headless rpi if you followed this tutorial series) | |
sudo ufw allow 80 | |
sudo ufw allow 443 | |
sudo ufw enable -> (y)es - we added port 22 over tcp - so our ssh session wont be terminated | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment