This tutorial provides a step-by-step guide on how to securely connect to your CentOS VPS remotely using SSH, covering key concepts and practical instructions.
centosssh
Small
VPS
2
vCPU
4 GB
Memory
40 GB
NVMe Disk
2048 GB
Traffic
10.90€
/month
* Up to 12GB RAM, 120GB NVMe Disk Space and 1Gbit/s Network Speed
#### Prerequisites
Before you begin, ensure you have:
- A CentOS VPS (This guide is tested with CentOS 8)
- A user account with sudo privileges
- Basic familiarity with the command line
- An SSH client (like OpenSSH on Linux/macOS or PuTTY on Windows)
#### Step 1: Find Your Server’s IP Address
To connect to your VPS, you need to know its public IP address. This information is typically provided by your hosting provider.
#### Step 2: Open Your SSH Client
Depending on your operating system, open your SSH client:
- **Linux/macOS:** Open a terminal window.
- **Windows:** Open PuTTY or a similar SSH client.
#### Step 3: Connect to Your Server
Use the SSH command to connect to your server. The basic syntax is:
```bash
ssh your_username@your_server_ip
```
Replace `your_username` with your actual username and `your_server_ip` with your server's IP address.
Example:
```bash
ssh john@192.0.2.1
```
If this is your first time connecting to the server, you will be prompted to verify the server's authenticity. Type `yes` and press Enter to continue.
#### Step 4: Enter Your Password
When prompted, enter the password for your user account. Note that the password will not be visible as you type for security reasons.
```plaintext
john@192.0.2.1's password:
```
#### Step 5: Basic SSH Commands
Once connected, you can run commands on your VPS. Here are a few basic commands to get you started:
- **Update system packages:**
```bash
sudo dnf update -y
```
- **Create a new directory:**
```bash
mkdir new_directory
```
- **List files in a directory:**
```bash
ls -la
```
#### Step 6: Secure Your SSH Connection
To enhance the security of your SSH connection, consider the following practices:
- **Disable root login:**
Open the SSH configuration file:
```bash
sudo nano /etc/ssh/sshd_config
```
Find the line `PermitRootLogin` and set it to `no`:
```plaintext
PermitRootLogin no
```
Save and exit the file, then restart SSH:
```bash
sudo systemctl restart sshd
```
- **Change the default SSH port:**
In the same SSH configuration file, find the line `#Port 22` and change it to a different port number, e.g., `Port 2222`.
```plaintext
Port 2222
```
Save and exit the file, then restart SSH:
```bash
sudo systemctl restart sshd
```
Ensure the new port is allowed in your firewall settings:
```bash
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
```
- **Use SSH key authentication:**
Generate an SSH key pair on your local machine:
```bash
ssh-keygen -t rsa -b 2048
```
Copy the public key to your VPS:
```bash
ssh-copy-id -i ~/.ssh/id_rsa.pub your_username@your_server_ip
```
Edit the SSH configuration file on your VPS to ensure `PasswordAuthentication` is set to `no`:
```bash
sudo nano /etc/ssh/sshd_config
```
Find the line `PasswordAuthentication` and set it to `no`:
```plaintext
PasswordAuthentication no
```
Save and exit the file, then restart SSH:
```bash
sudo systemctl restart sshd
```
#### Step 7: Disconnect from Your Server
When you are done, type `exit` to disconnect from your VPS:
```bash
exit
```
#### Conclusion
You have learned how to connect to your CentOS VPS remotely using SSH and implement basic security measures to protect your connection. Regularly review and update your SSH settings to ensure ongoing security.
**Additional Resources:**
- **SSH Documentation:** [https://www.openssh.com/manual.html](https://www.openssh.com/manual.html)
- **CentOS Documentation:** [https://www.centos.org/docs/](https://www.centos.org/docs/)