Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Create and Edit a File Over SSH with nano and vim

This guide shows how to make and change files on a server by typing commands.

Web Hosting2 min read12 steps5 screenshots

What is SSH?

SSH is a safe way to control a server from your own computer by typing commands. Think of it as a remote control that uses text. To log in, you use a terminal. Windows 10 and later have one. On Mac and Linux, open the Terminal app. Ask Hostvento support whether SSH is on your plan. Your login details are in your welcome email.

Log in

  1. Open your terminal.
  2. Type the command with your user name and server address:
ssh username@your-server-address

This connects you to the server. Enter your password when asked. You will not see the letters as you type, which is normal.

Using nano (easier)

Nano is a simple text editor that shows its keys at the bottom.

  1. Type this to create or open a file:
nano test.txt

If the file does not exist, nano makes it when you save.

Screenshot: If the file does not exist, nano makes it when you save.
  1. Type your text.
  2. Press Ctrl+O to save, then press Enter.
    Screenshot: Press Ctrl+O to save, then press Enter .
  3. Press Ctrl+X to leave nano.

Using vim (more powerful)

Vim has modes. In normal mode, keys are commands. In insert mode, you can type text.

Screenshot: Vim has modes. In normal mode, keys are commands. In insert mode, you can type text.
Screenshot: Vim has modes. In normal mode, keys are commands. In insert mode, you can type text.
  1. Open the file:
vim test.txt
  1. Press i to enter insert mode. You will see INSERT at the bottom.
    Screenshot: Press i to enter insert mode. You will see INSERT at the bottom.
  2. Type your text.
  3. Press Esc to return to normal mode.
  4. Type :wq and press Enter to save and quit.
  5. To quit without saving, type :q! and press Enter.

Check your file

cat test.txt

This prints the file contents on screen.

Make a backup before editing

cp config.php config.php.bak

This copies a file to a new name. If you break the original, you can restore the copy.

Warning: Editing the wrong system file can break your site or server. Always keep a backup of important files before you change them.

Quick recap

  • SSH lets you type commands on a server.
  • nano: open, type, Ctrl+O to save, Ctrl+X to exit.
  • vim: press i to type, Esc, then :wq to save and quit.
  • Use cat to read a file.
  • Copy a file with cp before you edit it.