Enable SSH – Ubuntu
Here is a step-by-step guide on how to enable SSH (Secure Shell) on Ubuntu:
Step 1: Open the Terminal
First, open the Terminal application on your Ubuntu system. You can do this by searching for “Terminal” in the Dash home, or by navigating to Applications > Accessories > Terminal.
Step 2: Install SSH
sudo apt update
sudo apt install openssh-server
Step 3: Configure SSH Server (Optional – If something must be configured)
(if nano is not installed you can install it via this command: sudo apt install nano)
- Open the configuration file:
sudo nano /etc/ssh/sshd_config
- Locate the following lines:
Port 22
PermitRootLogin no
PasswordAuthentication yes
Change:
Port 22: To a different port if desired (e.g., 2222)
PermitRootLogin no: To disable root login via SSH
PasswordAuthentication yes: To enable password authentication (for testing purposes)
Save and close the file. (CTRL + X)
Step 4: Create a New User
sudo adduser <username>
sudo usermod -a -G sudo <username>
Step 5: Generate SSH_Key_Pair
ssh-keygen -t rsa -b 4096 -C "<username>@<hostname>"
- Enter a passphrase for your key (optional)
Step 6: Add Public Key to authorized_keys
sudo nano ~/.ssh/authorized_keys
- Paste the public key from the
id_rsa.pub
file into the authorized_keys file.
Step 7: Configure Firewall
sudo ufw allow <port>
Default port for SSH is 22.
Step 8: Restart SSH Server
sudo systemctl restart ssh
Connect via SSH:
- Use a terminal client like PuTTY or Terminal to connect to your Ubuntu machine.
- Enter the hostname or IP address, port (e.g., 2222), username, and password (if not using key authentication).
Additional Tips:
- Use a strong passphrase for your key.
- Disable password authentication for production systems.
- Configure key-based authentication for multiple users.
- Consider using an client with key management features.
Troubleshooting:
- Check if the server is running. (run command: sudo systemctl status ssh)
- Verify the port is open.
- Ensure the public key is correctly added to authorized_keys.
- Check for permission issues.