How to configure SSH access on Ubuntu?

by monroe.bahringer , in category: Networking & Wireless , 2 years ago

How to configure SSH access on Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by adelia , 2 years ago

@monroe.bahringer 

To configure SSH access on Ubuntu, you can follow these steps:

  1. Install the SSH server: Open the terminal and run the following command:
1
2
sudo apt-get update
sudo apt-get install openssh-server


  1. Check the status of the SSH service:
1
sudo systemctl status ssh


This command should show you whether the SSH server is running or not.

  1. Configure SSH access: Edit the SSH configuration file using your favorite text editor (nano, vim, etc.)
1
sudo nano /etc/ssh/sshd_config


Make the following changes:

  • Change the port number (optional) to a different port than the default 22 for security reasons.
  • Set PermitRootLogin to no to disable SSH access for the root user.
  • Set PasswordAuthentication to no to disable password-based authentication and use only SSH keys for authentication.


Save the changes and close the file.

  1. Restart the SSH service:
1
sudo systemctl restart ssh


  1. Configure firewall rules: If you have a firewall enabled on your Ubuntu server, make sure to open the SSH port (default 22 or the one you set in step 3) to allow incoming connections:
1
sudo ufw allow ssh


That's it! You should now be able to connect to your Ubuntu server using SSH.

Member

by brock , 5 months ago

@monroe.bahringer 

Make sure to also set up SSH keys for more secure authentication. Here's how you can generate SSH keys and configure them for authentication:

  1. Generate SSH keys on your local machine:
1
ssh-keygen -t rsa


  1. Copy the public key to the Ubuntu server:
1
ssh-copy-id <username>@<your_server_ip>


  1. Log in to your Ubuntu server using SSH keys:
1
ssh <username>@<your_server_ip>


  1. Disable password authentication in the SSH configuration file to enforce SSH key-based authentication:
1
sudo nano /etc/ssh/sshd_config


Set PasswordAuthentication no, save the file, and restart the SSH service using sudo systemctl restart ssh.


With SSH keys configured, you can now securely access your Ubuntu server without using passwords.