How to use SSH and securely connect to your server

  • 7,000
  • Tác giả: admin
  • Ngày đăng:
  • Lượt xem: 7
  • Tình trạng: Còn hàng

This guide explains how vĩ đại establish an SSH (Secure Shell) connection vĩ đại access the command line of your server. While we’ll be using our WordPress Wetopi hosting service as an example, the same procedure applies vĩ đại any other situation. Keep reading!

Table of Contents

  • What is SSH and what is it for?
  • Enhancing WordPress development with SSH access
  • How vĩ đại connect via SSH
    • 1. Create an SSH client for remote access.
    • 2. Access data for SSH connection
    • 3. Initiate SSH connection
  • Connect via SSH with Private Key
    • 1. Prepare your server vĩ đại manage SSH keys
    • 2. Use OpenSSH vĩ đại generate the keys
    • 3. Save a copy of the public key on your remote server
  • Conclusion

What is SSH and what is it for?

Before delving into details, it’s important vĩ đại know that SSH enables you vĩ đại administer a server remotely and securely, without exposing your credentials or the data transferred between the client (e.g., your laptop) and the server.

Enhancing WordPress development with SSH access

Remote access via SSH (Secure Shell) allows you vĩ đại access the command line of your server. As a WordPress developer, using the command line enables you vĩ đại work more efficiently on tasks such as:

  • Moving files and directories.
  • Compressing and decompressing zip, tar, and other files.
  • Using the command line interface for WordPress, WP-CLI.
  • Working with development tools lượt thích Git or Composer.

At Wetopi, we provide remote access via SSH vĩ đại all users with “Professional” or “Agency” profiles.

How vĩ đại connect via SSH

1. Create an SSH client for remote access.

Depending on the operating system you’re using, you may need vĩ đại install an SSH client that allows you vĩ đại remotely access your server.

For Windows users, an SSH client isn’t included by mặc định. Thus, you’ll need vĩ đại tải về and install an external one lượt thích Putty.

Conversely, both Mac and Linux come equipped with a built-in tool that allows SSH access from the terminal without the need for additional software.

2. Access data for SSH connection

The basic data vĩ đại establish a connection via SSH is:

  • Host (Server): e.g. ssh.c.
  • Port: by mặc định port 21 is used. But in Wetopi we use dedicated ports, e.g.: 22022
  • User: e.g. we use the user www
  • Password: in Wetopi by mặc định you can access with a password, although later we will show you how vĩ đại connect using keys.

If you’re a Wetopi user, you will find all this data in the advanced options thực đơn of your server:

SSH remote access data

3. Initiate SSH connection

Using the connection data provided above, you can populate the fields in the Putty client or a similar program. Alternatively, if you have a terminal, open a window and lập cập the SSH application, passing the User, Host, and Port information as shown in this example:

ssh [email protected]. -p 22022

When trying vĩ đại connect using a password, SSH will tell you that “Host authenticity cannot be verified using keys”, ví it will then ask for a password.

Open ssh access using password

Also, if it is the first time we connect, the host is unknown and it will ask us vĩ đại confirm if we want vĩ đại proceed:

This key is not known by any other names Are you sure you want vĩ đại continue connecting (yes/no/[fingerprint])?

We select ‘yes’, and then it will prompt us for the password. Upon entering it, we will be immediately connected remotely vĩ đại the server .

Once you’re in the command line, the content and commands available vĩ đại you will be determined by your user profile. In Wetopi, the SSH user ‘www’ has the same privileges as the trang web user ‘www-data’. This arrangement ensures that any management tasks you perform on the WordPress tệp tin system won’t alter privileges, potentially causing issues.

In Wetopi, by mặc định, tools such as WP-CLI are instantly available, allowing you vĩ đại carry out WordPress maintenance and management tasks

Run WordPress Tasks with WP CLI

Connect via SSH with Private Key

SSH keys enable connections between two hosts without passwords, utilizing a pair of keys: one public and one private.

Continue reading vĩ đại learn the step-by-step process of generating and using keys for SSH connections.

1. Prepare your server vĩ đại manage SSH keys

(Note: If you are working with a Wetopi server, you can skip this step. Otherwise, continue reading.)

To work with SSH keys, you must first create the hidden .ssh folder in the home page directory of your user tài khoản on the remote server using the following command

mkdir -p ~/.ssh

Then, restrict the permissions of that directory vĩ đại ensure the keys are secure:

chmod 700 ~/.ssh

2. Use OpenSSH vĩ đại generate the keys

For enhanced security, always generate your key pair on your local computer rather kêu ca on the server.

For Windows users, while you can generate keys on the server, it’s imperative vĩ đại copy your keys vĩ đại your máy tính and then remove the private key from the server after its creation.

Both Mac and Linux systems come equipped with the ssh-keygen command from OpenSSH, which is designed for generating key pairs.

ssh-keygen -t rsa

ou will be prompted vĩ đại select a location vĩ đại save the keys. The mặc định location, typically your home page directory, is recommended. Simply press “Enter” vĩ đại choose this mặc định location.

Next, you’ll be asked for a passphrase. This step is optional; if you prefer not vĩ đại phối one, just press “Enter”. Following this, you’ll see a fingerprint and a “visual fingerprint” of your key. There’s no need vĩ đại record this information.

Upon completion, both the private and public keys will be saved in the .ssh directory.

3. Save a copy of the public key on your remote server

To transfer the public key, you can utilize the ssh-copy-id command, specifying the appropriate port, user, and host. Continuing with our example:

ssh-copy-id -p 22022 -i ~/.ssh/id_rsa.pub [email protected].

This process assumes you’ve saved your key pair using the mặc định name and location. If you chose a different name or location, replace the key path ~/.ssh/id_rsa.pub with the path vĩ đại your specific key.

When prompted, enter the password associated with your user tài khoản on the SSH server.

Send a copy of the public key using ssh-copy-id

You can now connect vĩ đại your server using the key pair. In our example, it won’t prompt you for a password:

Conclusion

Perfect! You’ve learned how vĩ đại connect via SSH.

Using SSH is a fundamental skill for secure server management. By understanding key generation and server setup, you can enhance the security and efficiency of your operations.

As you continue vĩ đại work with SSH, remember vĩ đại refer back vĩ đại this guide and seek help when needed. Proper server management is crucial for maintaining a safe online environment.

if you have any further questions, please tương tác us. We’ll be glad vĩ đại assit.

Don’t you have an tài khoản on Wetopi?

Free full performance servers for your development and test.
No credit thẻ required.

This might also interest you: