nano is the default text editor on most Linux servers. When you SSH into a server and need to edit a configuration file, a cron job, or wp-config.php, nano is the editor you are most likely to reach for. It is not the most powerful text editor (vim holds that title), but it shows its keyboard shortcuts at the bottom of the screen and does not require memorizing modes or commands to perform basic operations. You can open a file, make a change, save, and exit in under a minute without reading a manual.
This guide covers every operation you will actually use when editing files on a server.
Opening a file#
nano /etc/nginx/nginx.conf
This opens the file in nano. If the file does not exist, nano creates it when you save.
To open a file at a specific line number (useful when an error log tells you the problem is on line 47):
nano +47 /etc/nginx/nginx.conf
To open a file as read-only (prevents accidental edits):
nano -v /etc/nginx/nginx.conf
If the file requires root permissions to edit:
sudo nano /etc/nginx/nginx.conf
Most configuration files on a server are owned by root. If nano opens the file but the bottom of the screen shows “[ File ‘/etc/nginx/nginx.conf’ is unwritable ]”, you need sudo.
Navigation#
nano navigation uses the arrow keys for basic movement and keyboard shortcuts for larger jumps.
| Shortcut | Action |
|---|---|
| Arrow keys | Move cursor one character/line |
Ctrl+F
| Move forward one character (same as right arrow) |
Ctrl+B
| Move backward one character (same as left arrow) |
Ctrl+P
| Move to previous line (same as up arrow) |
Ctrl+N
| Move to next line (same as down arrow) |
Ctrl+A
| Move to beginning of current line |
Ctrl+E
| Move to end of current line |
Ctrl+Y
| Page up (scroll up one screen) |
Ctrl+V
| Page down (scroll down one screen) |
Ctrl+_
| Go to a specific line number (prompts for the number) |
Alt+\
| Go to the first line of the file |
Alt+/
| Go to the last line of the file |
The
Ctrl+_
shortcut (that is Ctrl + underscore, which on most keyboards is Ctrl+Shift+hyphen) is the most useful navigation shortcut. When an error message says “syntax error on line 142,” press
Ctrl+_
, type 142, and press Enter.
Saving a file#
Ctrl+O
This is “Write Out” (the O stands for Output). nano prompts you with the filename at the bottom of the screen. Press Enter to confirm and save to the same file. If you want to save to a different filename, type the new name before pressing Enter.
The bottom bar shows
^O Write Out
as a reminder. The
^
symbol means Ctrl in nano’s notation.
Save and exit in one step
Ctrl+X
If you have unsaved changes, nano asks “Save modified buffer?” Press
Y
for yes, then Enter to confirm the filename. This is the most common way to finish editing: make your changes, press
Ctrl+X
, press
Y
, press Enter.
If you want to exit without saving (discard changes):
Ctrl+X, then N
Press
Ctrl+X
, then
N
for no when asked to save. Your changes are discarded and the file remains as it was before you opened it.
Search#
Find text
Ctrl+W
This opens the search bar at the bottom. Type your search term and press Enter. nano jumps to the first match. To find the next occurrence, press
Ctrl+W
again and press Enter (the previous search term is remembered).
Search and replace
Ctrl+\
This opens the search-and-replace interface. nano prompts for the search term first, then the replacement term. After entering both, nano finds the first match and asks what to do:
-
Y– replace this occurrence and find the next -
N– skip this occurrence and find the next -
A– replace all remaining occurrences without asking
This is useful for bulk changes like replacing a domain name in a configuration file or changing a PHP version number across multiple lines.
Case-sensitive vs case-insensitive search
By default, search in nano is case-insensitive. To toggle case sensitivity, press
Alt+C
while in the search bar.
Regular expression search
Press
Alt+R
while in the search bar to toggle regex mode. This lets you search for patterns like
^server_name
(lines starting with “server_name”) or
listen.*443
(lines containing “listen” followed by “443”).
Copy and paste#
nano’s copy and paste works differently from what you might expect if you are used to
Ctrl+C
/
Ctrl+V
in a desktop application. In nano,
Ctrl+C
shows the cursor position, not copy.
Copy a single line
Alt+6
This copies (nano calls it “copy”) the current line into the cut buffer. The line stays in place. It is not visually highlighted or indicated.
Cut a single line
Ctrl+K
This cuts the current line (removes it from the file and puts it in the cut buffer). If you want to move a line,
Ctrl+K
to cut it, navigate to the destination, and
Ctrl+U
to paste it.
Paste
Ctrl+U
This pastes the contents of the cut buffer at the current cursor position. You can paste multiple times. The buffer is not cleared after pasting.
Copy or cut multiple lines
To copy or cut a block of text:
- Move the cursor to the start of the block
- Press
Alt+Ato set a mark (starts selecting) - Move the cursor to the end of the block (the selected text is highlighted)
- Press
Alt+6to copy the selection, orCtrl+Kto cut it - Navigate to where you want to paste
- Press
Ctrl+Uto paste
The mark-and-select approach (
Alt+A
) is how you select arbitrary text in nano. Without it,
Alt+6
and
Ctrl+K
only operate on the current line.
Select all
There is no single “select all” shortcut. To select the entire file:
- Press
Alt+\to go to the first line - Press
Alt+Ato set the mark - Press
Alt+/to go to the last line
The entire file is now selected. Press
Alt+6
to copy or
Ctrl+K
to cut.
Paste from system clipboard
When you are connected via SSH,
Ctrl+V
in nano means “page down,” not paste. To paste text from your local clipboard into nano over SSH:
- On macOS Terminal or iTerm2: Cmd+V
- On Windows Terminal or PuTTY: Right-click
- On Linux terminal emulators: Ctrl+Shift+V or middle mouse button
This pastes through the terminal emulator, not through nano. The text appears as if you typed it. For large pastes, nano may struggle because it processes each character individually. If you need to paste large amounts of text into a file, consider using SCP or SFTP to upload the file instead.
Undo and redo#
Alt+U Undo
Alt+E Redo
nano supports multiple levels of undo. Press
Alt+U
repeatedly to undo multiple changes.
Alt+E
redoes what you undid.
This was not always available in nano. Older versions (before 2.3.5) did not have undo. If
Alt+U
does not work, your server has a very old version of nano.
Line numbers#
To show line numbers:
nano -l /etc/nginx/nginx.conf
The
-l
flag displays line numbers in the left margin. This is helpful when cross-referencing error messages that reference specific line numbers.
To toggle line numbers while already in nano, press
Alt+N
.
To make line numbers the default, add this to your nano configuration:
echo "set linenumbers" >> ~/.nanorc
Syntax highlighting#
nano supports syntax highlighting for many file types (PHP, Python, Nginx, Apache, YAML, JSON, shell scripts). On most modern distributions, syntax highlighting is enabled by default for recognized file extensions.
If your files are not highlighted, check if the syntax files are installed:
ls /usr/share/nano/
You should see files like
php.nanorc
,
python.nanorc
,
sh.nanorc
, etc. If they exist but highlighting is not active, add this to
~/.nanorc
:
include "/usr/share/nano/*.nanorc"
Syntax highlighting makes it easier to spot errors in configuration files. A missing quote or an unclosed bracket is often visible as a color change that does not look right.
Useful nano configuration#
Create or edit
~/.nanorc
to customize nano’s behavior:
# Show line numbers
set linenumbers
# Enable mouse support (click to position cursor)
set mouse
# Convert tabs to spaces (important for YAML and Python)
set tabstospaces
set tabsize 4
# Enable soft line wrapping (long lines wrap visually)
set softwrap
# Show trailing whitespace
set trimblanks
# Enable syntax highlighting
include "/usr/share/nano/*.nanorc"
nano vs vim#
Both editors are available on virtually every Linux server. The choice depends on your needs.
Use nano when:
- You need to make a quick edit to a configuration file
- You are not a frequent terminal user and want something intuitive
- You want to see keyboard shortcuts on screen without memorizing them
- The edit is simple (change a value, uncomment a line, add a line)
Use vim when:
- You edit files on servers frequently and want maximum efficiency
- You need powerful search and replace, macros, or multi-file editing
- You are comfortable with modal editing (normal mode, insert mode, visual mode)
- Speed of editing matters to you
For most server administration tasks (editing Nginx configs, changing PHP settings, modifying wp-config.php), nano is sufficient. Vim is more powerful but has a steep learning curve that is not justified for occasional config file edits.
Quick reference#
| Shortcut | Action |
|---|---|
Ctrl+O
| Save (write out) |
Ctrl+X
| Exit (prompts to save if modified) |
Ctrl+W
| Search |
Ctrl+\
| Search and replace |
Ctrl+K
| Cut current line |
Alt+6
| Copy current line |
Ctrl+U
| Paste |
Alt+A
| Start selecting (set mark) |
Ctrl+_
| Go to line number |
Alt+U
| Undo |
Alt+E
| Redo |
Ctrl+Y
| Page up |
Ctrl+V
| Page down |
Ctrl+A
| Beginning of line |
Ctrl+E
| End of line |
Alt+\
| First line of file |
Alt+/
| Last line of file |
Alt+N
| Toggle line numbers |
Alt+C
| Toggle case sensitivity in search |
Alt+R
| Toggle regex in search |
On Hostney, nano is available in every SSH container. Connect via SSH (Terminal Access in the control panel) and use nano to edit any file in your hosting account. For copying files rather than editing them in place, use
cp
to make a backup before editing configuration files.