Connect Securely to your Web Server
We at Ally Drez Web & IT Services do not recommend using your root account to make direct connections to your webserver. We also disable this feature for all shared hosting. For this reason, we will provide our best practice policy in teaching you how to connect to your server.
You can use any means to terminal into your webserver be it a VPS or dedicated.
This is the command line to connect once all your steps have been completed:
ssh -p <portnumber> firstname.lastname@example.org
Step 1 is to change your port number from the default 22
To Change the SSH Port for Your Linux Server (Apache or Nginx)
- Connect to your server via SSH
- Switch to the root user
- Run the following command:
- Locate the following line:
# Port 22
- Remove # and change 22 to your desired port number.
- Restart the sshd service by running the following command:
service sshd restart
Step 2 is to create a private key to install on your server.
Generating an SSH key – MAC or Linux
Open terminal and run the following command.
ssh-keygen -t ed25519 -o -a 100
The keypair will be written to $HOME/.ssh/. It consists of two files: the private key file and the public key-file:
Generating an SSH key – Windows
To generate an SSH key with PuTTYgen, download Putty and follow these steps:
- Open the PuTTYgen program, which is apart of the Putty itself.
- Type of key to generate: select ED25519
- Then click the Generate button. You will then see a progress bar. Once it is full, PuTTYgen will generate your key pair.
- In the Key passphrase field, type a passphrase. You will have to confirm it by typing it twice. Also, keep in mind you do not want to forget your password. Otherwise, you will have to start over.
- Next, click the save private key (Putty specific version with public and private key provided) and public key (gives you a key you can use anywhere) buttons and save both keys. Keep in mind, you need the private key to connect to your server, so be sure to save it in a place you will find it!
- To generate an OpenSSH version:
- Go to the menu called “conversions” and export OpenSSH Key
Step 3 put the key on the server
Put the public key you saved earlier, at the bottom of this text file /username/.ssh/authorized_keys
Push i to enter edit mode.
Past public key to the bottom of the file.
Push :wq to save the file.