sudo nano /etc/example.conf, make your change, press Ctrl+O then Enter to save and Ctrl+X to exit. In vim, run sudo vim /etc/example.conf, press i to start typing, then press Esc and type :wq and Enter to save and quit, or :q! to quit without saving.
Before you start
- Connect with SSH. System files in
/etcbelong to root, so open them withsudo(root can leave it out). - Copy a config file before you change it, so you can go back:
Which editor should I use?
Use nano if you are new to Linux: the shortcuts are listed at the bottom of the screen. Use vim if you already know it or want a powerful editor;vi or vim is present on almost every server, including minimal installs and rescue systems.
If an editor is missing, install it:
- Ubuntu / Debian
- AlmaLinux / Rocky
How to edit a file with nano
1
Open the file
2
Make your change
Move with the arrow keys and type normally. Paste text you copied on your computer with your terminal’s paste (usually right-click, or
Ctrl+Shift+V).3
Save
Press
Ctrl+O, check the file name at the bottom, and press Enter. Ctrl+S saves without the question.4
Exit
Press
Ctrl+X. If there are unsaved changes, nano asks: press Y to save or N to discard.nano shortcuts
In nano’s help bar,^ means Ctrl and M- means Alt.
To open a file at a line, for example line 42, use
nano +42 /etc/ssh/sshd_config. Show line numbers with nano -l.
How to edit a file with vim
vim has modes. It opens in normal mode, where keys are commands. You type text only in insert mode.1
Open the file
2
Go to insert mode
Move to the right place with the arrow keys and press
i. The bottom line shows -- INSERT --. Now type your change.3
Go back to normal mode
Press
Esc.4
Save and quit
Type
:wq and press Enter.How to exit vim
vim commands (normal mode)
New to vim? Run
vimtutor for a 30-minute interactive lesson.
How to check it worked
Print the file to confirm your change was saved:sudo nginx -t or sudo sshd -t. These print nothing (sshd) or syntax is ok (nginx) when the file is valid.
How to change the default editor
Programs such ascrontab -e, visudo and git open your default editor.
Frequently asked questions
I’m stuck in vim. How do I get out?
PressEsc two or three times, type :q! and press Enter. This quits without saving.
nano says “Permission denied” when I save. Why?
You opened a file that belongs to root withoutsudo. Exit with Ctrl+X, answer N, and open it again with sudo nano. Or save a copy to your home folder with Ctrl+O and a new name.
What is the “.swp” warning when I open a file in vim?
vim found a swap file from an editing session that crashed or is still open. If nobody else is editing the file, pressR to recover or D to delete the swap file, then continue.
Can I edit server files on my own computer instead?
Yes. Use an SFTP client such as WinSCP or FileZilla; see transfer files with SFTP. Check that it saves with Linux line endings (LF).Related guides
VPS and dedicated server guides
Every server guide in one place.
Essential Linux commands
The commands you use every day.
Schedule tasks with cron
Uses your default editor.
Environment variables and .bashrc
Edit your shell settings.
Checked against the official GNU nano cheat sheet and the Vim documentation on 4 November 2026; tested with nano 7.2 and Vim 9.1 on Ubuntu 24.04 LTS. Shortcuts can differ in other versions.
Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026