Technology Encyclopedia Home >How to setup SSH remote access on Alpine Linux?

How to setup SSH remote access on Alpine Linux?

To set up SSH remote access on Alpine Linux, follow these steps:

  1. Install OpenSSH Server: First, you need to install the OpenSSH server package. You can do this by running the following command in your Alpine terminal:

    apk add openssh-server
    
  2. Create SSH Directory: Ensure that the /var/run/sshd directory exists, as the SSH server needs it to run. You can create it manually if it doesn't:

    mkdir -p /var/run/sshd
    
  3. Configure SSH: Edit the SSH configuration file to set up your preferences. The configuration file is located at /etc/ssh/sshd_config. You might want to change the default port, disable root login, and set up password authentication or key-based authentication. For example:

    nano /etc/ssh/sshd_config
    

    Modify or add the following lines as needed:

    Port 2222
    PermitRootLogin no
    PasswordAuthentication yes
    
  4. Generate SSH Keys (Optional but Recommended): For enhanced security, it's recommended to use SSH keys instead of passwords. Generate an SSH key pair on your local machine if you don't already have one:

    ssh-keygen -t rsa
    

    Then, copy the public key to your Alpine Linux machine:

    ssh-copy-id -i ~/.ssh/id_rsa.pub user@alpine_ip_address
    
  5. Start and Enable SSH Service: Start the SSH service and enable it to start on boot:

    rc-service sshd start
    rc-update add sshd
    
  6. Test SSH Access: Finally, test your SSH connection from another terminal window:

    ssh user@alpine_ip_address -p 2222
    

Example: Suppose your Alpine Linux machine has an IP address of 192.168.1.100. After setting up SSH as described, you would connect to it using:

ssh user@192.168.1.100 -p 2222

Cloud Service Recommendation: If you're managing multiple Alpine Linux instances or need scalable and reliable hosting, consider using Tencent Cloud's Virtual Private Cloud (VPC) service. It provides a secure and isolated network environment where you can deploy your Alpine Linux instances and manage SSH access efficiently.