How to Set Up SSH on Linux and Test Your Setup: A Beginner’s Guide
If you’re new to Linux, you might be wondering how you can securely access your server or other devices remotely. One way to do this is by using SSH or Secure Shell, which is a protocol for secure communication between two computers. This article will guide you through how to set up SSH on your Linux device and test your setup.
Step 1: Install SSH
Most Linux distributions will come with OpenSSH pre-installed, but if you’re not sure, you can use the following command to check:
“`sudo apt-get install openssh-server“`
This command will install OpenSSH on Ubuntu and other Debian-based distributions. If you are using a different distribution, the command may vary.
Step 2: Check the Status of SSH
After installation, you can check the status of SSH by running the following command:
“`sudo systemctl status ssh“`
If the service is running, you will see that it’s active and running. If not, you can start the service using the following command:
“`sudo systemctl start ssh“`
Step 3: Set up SSH Keys
Next, you will need to set up SSH keys. SSH keys are a more secure way of logging into your server because they don’t require a password. You can generate SSH keys using the following command:
“`ssh-keygen -t rsa“`
This will generate a public and private key in your home directory under .ssh/id_rsa and .ssh/id_rsa.pub, respectively.
Step 4: Copy the Public Key to the Server
Now that you have generated your SSH keys, you will need to copy the public key to the server. This can be done with the following command:
Replace “username” with your username and “server” with the IP address or hostname of your server.
Step 5: Log in to the Server
Once you have copied your public key to the server, you can log in to the server securely using the following command:
This will log you in to the server using your SSH key, without requiring a password.
Step 6: Test Your Setup
To test your setup, you can try connecting to your server from a different computer using the following command:
If everything is set up correctly, you should be able to log in without requiring a password.