The Developer’s Guide to Start Using SSH
Tags: webdev, ssh, security
Published: 2023-06-15 17:35:56

For most WordPress users, the most familiar way to connect to your site will be via the [WordPress dashboard and admin screens](https://kinsta.com/knowledgebase/wordpress-admin/), combined with [SFTP](https://kinsta.com/knowledgebase/how-to-use-sftp/) and [phpMyAdmin](https://kinsta.com/docs/wordpress-phpmyadmin/) to access the database

But SSH might just prove to be one of the most valuable tools in your WordPress toolkit.

If you want to speed up your workflow, you’ll find that learning how to use SSH to connect to your WordPress site will make you more efficient.

Let's dive in.

## **Tools You Need to Connect to Your Site via SSH**

To start, you’ll need to use either the terminal or an SSH client. These work in very similar ways.

### **Connecting via the Terminal on macOS or Linux**

The Terminal is an application that comes with Linux or macOS, that allows you to use the command line to [send commands](https://kinsta.com/blog/linux-commands/), either to your machine or to a remote server.

It isn’t a graphical interface so you won’t be using a mouse. Instead, you type in text commands. For a first-time user, it can be little disconcerting, as you’re probably used to seeing visual representations of your commands. But once you get used to it, you’ll find it quicker.

If you worked with computers in the days before graphical user interfaces, using systems such as Microsoft’s MS-DOS, you might be familiar with this kind of interface. The good news is that the Terminal gives you many more options than MS-DOS did!

To open the Terminal on Mac, open Spotlight and type **Terminal**. You can also access it via **Applications &gt; Utilities**.

![How to use SSH: Finding Terminal on Mac](https://kinsta.com/wp-content/uploads/2019/12/Finding-Terminal-on-Mac-1-1.jpg align="left")

To open Terminal on Linux, find it in the **Applications** menu. If it isn’t immediately obvious, type **Terminal** into the prompt to find it.

### **Connecting via an SSH Client on Windows**

An SSH client is a program that you’ll need to install if you’re running Windows, in order to connect via SSH.

The most popular SSH client is [PuTTY](https://www.putty.org/). You’ll need to download and install that before you can access your site from Windows.

![How to use SSH: PuTTY](https://kinsta.com/wp-content/uploads/2019/12/Putty-1.jpg align="left")

#### **Installing the Putty SSH Client on Windows**

Start by going to the [PuTTY download page](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html).

![How to use SSH: The PuTTY download page](https://kinsta.com/wp-content/uploads/2019/12/Putty-download-page-1.jpg align="left")

From here, choose the package that corresponds to your version of Windows. If you aren’t sure whether to download the 32-bit or 64-bit version, check out the [FAQ page.](https://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html#faq-32bit-64bit) If in doubt, the 32-bit version is the safer option.

Click on one of the two options under **MSI (‘Windows Installer’)**. The file will download to your machine and run the installer.

Once PuTTY has installed, open it and you can then use it to connect to your site.

## **How to Connect to Your Server via the Command Line**

Once you’ve found or installed the Terminal or an SSH client, the next step is to connect to your remote site.

In either Terminal or an SSH client, you use the **command line** to connect and send commands to your server. That’s the terminology I’ll use from now on, instead of referring to Terminal or an SSH client.

To do this, you’ll need four pieces of information:

* Server address.
    
* Username.
    
* Password.
    
* Port.
    

The server address is usually your domain name or IP address. If your site is hosted with Kinsta, use your [IP address](https://kinsta.com/docs/ipv4-address/).

The username and password will be your FTP username and password, **not the ones for your WordPress admin**.

The port will be provided by your hosting provider. In some cases, a default port is used, but for [extra security at Kinsta](https://kinsta.com/knowledgebase/malware-security/), we use different ports for different sites.

In [MyKinsta](https://kinsta.com/mykinsta/), you can find the details by selecting your site and finding the SFTP/SSH section of the Info screen.

![MyKinsta SSH](https://kinsta.com/wp-content/uploads/2019/12/MyKinsta-SSH-1.jpg align="left")

Just copy this and paste it into the command line.

Once you’ve done that, you will be prompted for your password. Copy that from MyKinsta and you’ll be given access to your server.

You’ll see a screen that looks something like this:

![Kinsta SSH starting screen](https://kinsta.com/wp-content/uploads/2019/12/Kinsta-SSH-starting-screen-1.jpg align="left")

If you’re not with Kinsta hosting, your screen will look a little different, but will still give you access to your server.

## **How to Use SSH to Interact with Your Site**

Now you can start using SSH to interact with your server and your site. There are a [number of SSH commands](https://kinsta.com/blog/ssh-commands/) you can use as well as the commands provided by the [WordPress Command Line Interface (WP-CLI)](https://kinsta.com/blog/wp-cli/).

<aside><h3 id="important">Important<a class="anchor-hash" href="https://kinsta.com/blog/how-to-use-ssh/#important"></a></h3><p>SSH is a very powerful tool and if you aren’t careful, you could break your site. It will let you add and delete files, so if you enter the wrong command, you could lose content or delete all your images, for example. Always use it with caution and make sure you<span> </span><a href="https://kinsta.com/docs/wordpress-backups/">backup your site</a><span> </span>before using it.</p></aside>

### **Basic SSH Commands**

SSH comes with a range of commands you can use to connect and interact with your server.

Once you’ve looked into your server via the command line, you simply type in SSH commands in the same way you would do if you were using Terminal to interact with your own computer.

Let’s take a look at some of the most useful SSH commands you could start using.

* [The ls Command](https://kinsta.com/blog/how-to-use-ssh/#ls)
    
* [The cd Command](https://kinsta.com/blog/how-to-use-ssh/#cd)
    
* [The mkdir Command](https://kinsta.com/blog/how-to-use-ssh/#mkdir)
    
* [The touch Command](https://kinsta.com/blog/how-to-use-ssh/#touch)
    
* [The cat Command](https://kinsta.com/blog/how-to-use-ssh/#cat)
    
* [The rm Command](https://kinsta.com/blog/how-to-use-ssh/#rm)
    
* [The cp Command](https://kinsta.com/blog/how-to-use-ssh/#cp)
    
* [The mv Command](https://kinsta.com/blog/how-to-use-ssh/#mv)
    

#### **The ls Command**

Use the `ls` command to get a list of the files and directories in your current location. You can add more to the command to get more information:

* `ls -l` displays the details of the files, such as size, modified date and time, the owner, and the permissions.
    
* `ls -a` shows [hidden files](https://kinsta.com/blog/show-hidden-files/) and directories.
    

![How to use SSH: The ls command](https://kinsta.com/wp-content/uploads/2019/12/ls-command-2.jpg align="left")

#### **The cd Command**

Use the `cd` command to change directories. You’ll be taken to the new directory and the command line will indicate where you are:

![The cd command](https://kinsta.com/wp-content/uploads/2019/12/The-cd-Command.jpg align="left")

You can then use `ls` again to find out what’s in the new directory.

You can use `cd` to move down more than one directory or to move up or across directories. To go up, enter two dots after `cd` like this:

```bash
cd ..
```

And to go to a specific directory, type the full directory path such as:

```bash
cd public/wp-content/themes
```

#### **The mkdir Command**

Use the `mkdir` command to create a new directory. So if I’m in the themes directory, I could create a new directory for [a new theme](https://kinsta.com/blog/how-to-install-a-wordpress-theme/):

```bash
mkdir mytheme
```

#### **The touch Command**

Once I’ve created my new directory, I could add a new file to it using the touch command:

```bash
touch style.css
```

#### **The cat Command**

To display the contents of a file, use the `cat` command.

![How to use SSH: The cat command](https://kinsta.com/wp-content/uploads/2019/12/cat-command-1.jpg align="left")

#### **The rm Command**

Use the `rm` command to remove a file or folder. Use with caution, as **this can’t be undone**:

```bash
rm style.css
```

#### **The cp Command**

The `cp` command is used to copy files and folders. You need to provide the name of the file or folder and the location where you want to copy it.

```bash
cp [options] [source] [destination]
```

You can also add options at the beginning of the command, but don’t need to. So to copy the **footer.php** file from one theme to another when you’re in the wp-content directory, you would use this:

```bash
cp /themes/theme1/footer.php /themes/theme2/
```

Don’t add a name for the destination file. If you do, and there’s already a file with that name at that destination, then the file will be overwritten with the contents of the file you’re copying.

If you don’t include a filename in the detonation and that file already exists, then you will get an error message and the copy won’t take place.

I’ve already mentioned that there are some optional elements you can add at the beginning of this command. These are:

* `-f`: if you don’t have write permission for the destination file, it’ll be deleted and the command will create a new file.
    
* `-u`: copy the source file only if it is newer than the destination file.
    
* `-n`: will not overwrite an existing file.
    
* `-a`: archive the files.
    
* `-R`: for folders only, copy all the files and folders inside that folder.
    

#### **The mv Command**

As an alternative to copying a file, you can move it using the `mv` command. For this, you just provide the source and destination: there are no options.

```bash
mv /themes/theme1/footer.php /themes/theme2/
```

This will remove the **footer.php** file from theme1 and move it to theme2. If you do this with a folder, it will always move the files and folders within that directory too.

You can find information about more SSH commands in the [SSH documentation](https://www.ssh.com/ssh/command/).

### **Using WP-CLI to Interact with Your Site**

In addition to the standard [SSH commands](https://kinsta.com/blog/ssh-commands/), WordPress also gives you the WP-CLI interface, which provides even more commands. This includes interacting with files and folders, the admin options, and [your database](https://kinsta.com/knowledgebase/wordpress-database/).

With Kinsta, WP-CLI comes with your hosting and you can start using it straight away. If your hosting provider doesn’t give your WP-CLI, you can install it by following the steps in this [guide to WP-CLI](https://kinsta.com/blog/wp-cli/).

## **How to Generate a New SSH Key Pair for Extra Security**

Generating an SSH key pair adds an [extra layer of security](https://kinsta.com/blog/wordpress-security/) when compared to using your username and password to connect to SSH. You do it from within the Terminal or your SSH client. Here’s how.

Generating a key pair involves three steps:

1. Generate the key pair in Terminal or in your SSH client.
    
2. Add the key pair to your hosting account – in MyKinsta you do this via the **User Settings** screens.
    
3. Connect to your server in Terminal or your SSH client using the key pair.
    

![Adding SSH key in MyKinsta](https://kinsta.com/wp-content/uploads/2019/12/Adding-SSH-key-in-MyKinsta.jpg align="left")

You can find full instructions on doing this in our [guide to generating SSH key pairs](https://kinsta.com/docs/connect-to-ssh/#generate-ssh-key-pair-windows) for macOS, Linux, and Windows**Summary**

Using SSH to connect to your server and your WordPress site will make you more efficient than relying on the WordPress admin interface, FTP, and even [phpMyAdmin](https://kinsta.com/docs/wordpress-phpmyadmin/).

Follow the steps above to connect to your server via SSH and you’ll find you can do more on your site without having to switch between applications or browser windows.

Now it’s your turn: what’s your preferred terminal command you use on a daily basis? Let us know in the comments!