Creating and editing a file via SSH - Gregg Hosting

The affects of Web Hosts on Your Business Website

Here're ways your choice of web hosting service provider impacts the performance of your business:


check

Website loading speed

check

Uptime and availability

check

Customer support

check

Security

check

Server location

Creating and editing a file via SSH

Creating and editing a file via SSH

Overview

When signed into a GreggHost server using SSH, there are a number different ways to create and edit files. This article will show you how to utilize two different text editors:

The best option for novices is nano.
vim has more functionality than nano, but it’s also more difficult to learn. For expert users, vim is a decent option.
If you’re not sure how to edit files in a terminal, check out this article:

FTP file creation and editing
This article just serves as an example of how to use SSH to create and edit a file. Make sure to choose your actual file and edit it with whatever material you require when following these instructions.

Using ‘nano’ to create and edit a file

Before you begin

Before you continue, please note that the next section is also available as a video tutorial:

 

Nano is more user-friendly than vim, making it an excellent alternative for newcomers. To use nano to create and edit a file, follow the steps below.

Creating or editing a file using ‘nano’

Use SSH to connect to your server.
To create a file, go to the directory where you wish to save it, or update an existing one.
After typing nano, type the file’s name. For instance, if you want to create (or update) a new file called index.html, type:
$ nano index.html [server]
A new file named index.html appears:
vim-nano-setup-01.png
Begin entering your information into the file.
vim-nano-setup-02.png
Hold down the Ctrl key and press the letter O (Ctrl + O) when you’re ready to save the file.
The prompt’s bottom section asks you to confirm the file’s name, which is already set to index.html.
To save, press the Enter key on your keyboard.
To close nano and return to your shell, hit Ctrl + X when you’re done.
Creating and editing a file using ‘vim’
Before you start, make sure you have everything you need.
The next section can also be seen as a video tutorial:

 

As previously stated, vim has more tools for editing files, but it is also more difficult to learn. Only advanced users with previous experience working in the Linux shell should use vim.

Using ‘vim’ to create and edit a file \sLog into your server via SSH.
Navigate to the directory where you want to create the file or where you want to make changes to an existing file.
Then type vim, followed by the file’s name. For instance, if you want to create (or edit) a new file called index.html, type [server]$ vim index.html.
Because you can’t input into the file yet, the vim editor may appear confusing at first:
vim-nano-setup-03.png
To enter INSERT mode in vim, press the letter I on your keyboard.
On the bottom left, it now says — INSERT —:
vim-nano-setup-04.png
Begin typing into the document.
Press the ESC key after you’re done modifying the file. This exits INSERT mode, and — INSERT — is no longer visible in the bottom left corner of your terminal.
Type a colon (:) followed by wq to save the file. As an example,