Creating and Editing a File via SSH on Ubuntu

There are many ways to to create and edit files via SSH when logged on to Linux terminal. Many of our posts on this blog are created and demonstrated via SSH or the command terminal. If you’re a student or a new user, managing files via SSH terminal can be daunting.

This brief tutorial is going to show you how to use Nano and Vim editors to manage files on Ubuntu. These two editors are the most used on Linux systems:

nano – best choice for new beginners

vim – has more features than nano, but difficult to use. It’s mostly for advanced Linux users.

So, if you want to learn now about these two editors, please continue below

For those still uncomfortable using the command line terminal, can always use FTP client like FileZilla or others to edit files.

Creating and Editing Files via Nano

As I said earlier, nano is easier to use than vim. New users should probably always use nano to edit and manage file on Linux terminal. To create a new file using nano on Linux systems, run the commands below

nano filename.txt

If the file is being creating in a folder owned by the root user, you may have to prefix it with sudo.

sudo nano filename.txt

After running the commands above a new blank file named filename.txt will opened and ready to type into.

ubuntu vim nano

All you have to do is begin typing into the file.

To save what you typed, press Ctrl + O

At the bottom you should see a prompt to confirm the fileaname.txt to save as. To save the content in the file, press Enter.

After saving the content in the file, press Ctrl + X to exit or close nano and return to the command shell.

The same steps above can be used to manage existing files. On existing file, type the commands below:

nano existingfile.txt

That should open the existing file with its content. Make your changes in the file by the arrow buttons on the keyboard to navigate.. then after making editing the file, press Ctrl + O to save and Ctrl + X to exit or close the file.

Creating or Editing Files via Vim

Vim on the other hand has more features but difficult to use especially for new users and students. To create a new file using vim, run the commands below

vim filename.txt

or run the commands below to create a new file in the root directory owned by the root user

sudo vim filename.txt

When you run the command above new file named filename.txt will be opened waiting for vim commands.

To begin inserting content into new file, type i on the keyboard. The prompt should change to INSERT as shown below.

Now you can begin typing into the editor.

When you’re done typing hit the ESC key to exit the INSERT mode.

Back at vim read-only mode, type the keys below to save the changes and exit vim editor.


After the typing the keys above, you should get a prompt to save the file. Press Enter to save.

Congratulations! You’ve just used nano and vim to manage file on Linux systems.

You may also like the post below:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.