SSH - Weber-State-Submarine-Project/Submarine GitHub Wiki

Setting Up SSH

To SSH into any Ubuntu computer, including the Raspberry Pi, you must set up the OpenSSH Server.

Steps to Install & Setup:

  1. Update the System:
    Run the following commands:

    sudo apt update
    sudo apt upgrade
    
  2. Install the OpenSSH Server:
    Run the following command:

    sudo apt install openssh-server
    
  3. Configure Firewall Rules for SSH:
    Check the status of UFW: sudo ufw status. If UFW is inactive, enable it with the following command: sudo ufw enable. Next, allow inbound SSH connections to the firewall:

    sudo ufw allow ssh
    
  4. Change the Default SSH Port:
    Typically, the default port is 22, but we will be changing it to increase security. First, backup the original SSH config:

    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
    

    Then, access the config file:

    sudo nano /etc/ssh/sshd_config
    

    Find the line Port 22, change 22 to a number between 1024 and 65535, and remove the #.

  5. Configure Firewall Rules for the Custom SSH Port:

    sudo ufw delete allow ssh
    sudo ufw allow <# from step 4>/tcp
    
  6. Restart the SSH Service:

    sudo systemctl restart ssh
    
  7. Verify the Configuration:

    sudo systemctl status ssh
    

You should now be able to SSH using openssh-server:

ssh -p <# from step 4> <username of account on device>@<ip of device>

Source