SSH & Terminal Access

Advanced Troubleshooting with nano: Navigating and Editing with Precision

By the Domain India teamPublished 9 min read
Knowledge base article
Contents (10 sections)

nano is the friendly terminal text editor found on almost every Linux server. Beyond basic editing, it can open a file at an exact line, search with regular expressions, replace text across a file, indent blocks and replay recorded keystrokes, which is exactly what you need when fixing a configuration file under pressure. This guide covers those techniques, with the shortcuts that really exist and notes on which nano versions have them.

Key takeaways

Open a file at a known line with nano +LINE file, jump inside it with Ctrl+_ (or Alt+G), search with Ctrl+W and toggle regex with Alt+R, and replace with Ctrl+\ then A for all. Mark text with Alt+A, cut with Ctrl+K and paste with Ctrl+U. Use less or grep -n for big logs and nano for the fix. Server config editing applies to your own VPS; on shared hosting you edit only your own files.

1. Where this applies

  • Your own VPS or server: you have root access, so you can edit system files such as web server, firewall and service configuration. Everything in this guide applies. Domain India VPS plans are self-managed.
  • Domain India shared hosting: you cannot change server configuration. If jailed SSH is enabled on your account, you can use nano on your own files, such as .htaccess, wp-config.php or a script. Jailed SSH is available on every shared hosting plan; it is off by default, so ask support to enable it. Measured in September 2026, the jailed shell on our cPanel and DirectAdmin servers has nano 2.9.8, so the newest features below are not available there.

Check your version first:

bash
nano --version

Enterprise Linux 8 systems (AlmaLinux, Rocky Linux, CloudLinux 8) ship nano 2.9; current Debian and Ubuntu releases ship nano 7 or later.

2. Open a file exactly where you need it

bash
nano +120 /etc/nginx/nginx.conf        # open at line 120
nano +120,15 /etc/nginx/nginx.conf     # line 120, column 15
nano -l ~/public_html/.htaccess        # show line numbers
nano -v /etc/ssh/sshd_config           # view only, no accidental edits

When an error message names a line, for example "syntax error in line 120", nano +120 puts the cursor right on it.

3. Read big logs with the right tool

nano loads the whole file into memory, so it is slow on large logs and you should never edit a log that a service is writing to. Find the line with other tools, then use nano for the configuration fix.

bash
grep -n "PHP Fatal" error_log | tail -n 5     # find matching lines with numbers
less +G /var/log/nginx/error.log              # open at the end; / to search, q to quit
journalctl -u nginx --since "1 hour ago"      # systemd service logs
tail -f /var/log/messages                      # follow a log live

Log locations differ by system: Debian and Ubuntu use /var/log/syslog and /var/log/apache2/, while RHEL-based systems use /var/log/messages and /var/log/httpd/. On shared hosting, see Reviewing error logs in cPanel and DirectAdmin.

4. Move around a file fast

ActionShortcutNotes
Go to line (and column)Ctrl+_ or Alt+GType 120 or 120,15 then Enter
Top or bottom of fileAlt+\ and Alt+/Ctrl+Home and Ctrl+End also work in most terminals
Next or previous wordCtrl+Space and Alt+SpaceCtrl+Right and Ctrl+Left in newer versions
Page down or upCtrl+V and Ctrl+YPgDn and PgUp also work
Show cursor positionCtrl+CShows line, column and character count
Place and jump to anchorsAlt+Insert, then Alt+PgUp or Alt+PgDnnano 6 and later only

Anchors work like temporary bookmarks: place one on a line you keep returning to, such as an SSL block, and jump back to it later. They are not available in nano 2.9.

5. Search and replace precisely

  1. Search.
    Press Ctrl+W, type the text and press Enter. Alt+W finds the next match.
  2. Match case or use regex.
    At the search prompt, Alt+C toggles case-sensitive matching and Alt+R toggles regular expressions.
  3. Match whole words.
    With regex on, search for \bAllowOverride\b so partial words are skipped.
  4. Replace.
    Press Ctrl+\, type the text to find, press Enter, type the replacement and press Enter. At each match, press Y to replace, N to skip, or A to replace all.
  5. Undo if needed.
    Alt+U undoes and Alt+E redoes.

Example: to change every 127.0.0.1 to a new address, press Ctrl+\, enter 127.0.0.1, enter the new IP, then press A. With regex on, escape the dots (127\.0\.0\.1), because an unescaped dot matches any character.

6. Mark, copy, cut, paste and indent

ActionShortcut
Start or stop marking a blockAlt+A (or Ctrl+^)
Copy the marked block, or the current lineAlt+6
Cut the marked block, or the current lineCtrl+K
PasteCtrl+U
Indent or unindent the marked linesAlt+} and Alt+{
Comment or uncomment linesAlt+3 (nano 2.9 and later, where the file type is known)

To duplicate a server block in an nginx configuration, mark it with Alt+A, move to the end, copy it with Alt+6, move to where it should go and press Ctrl+U. Pressing Ctrl+K several times in a row collects the lines together, so one Ctrl+U pastes them all.

7. Record and replay keystrokes

nano 2.9 and later can record a sequence of keys and replay it:

  1. Press Alt+: to start recording.
  2. Do the edit once, for example: search for the next AllowOverride None, move to None and replace it with All.
  3. Press Alt+: again to stop.
  4. Press Alt+; to replay the sequence at the next spot, as many times as you need.

For one simple text change across a file, search and replace (section 5) is faster; macros suit edits that involve moving the cursor.

8. Make nano your own with nanorc

Put settings in ~/.nanorc, one per line with comments on their own lines, for yourself, or /etc/nanorc for every user on your own server:

bash
# Always show line numbers
set linenumbers
# Keep the indentation of the previous line
set autoindent
# Four-space tabs, typed as spaces (YAML does not allow tabs)
set tabsize 4
set tabstospaces
# Wrap long lines on screen without changing the file
set softwrap
# Keep the previous version as filename~ when saving
set backup
# Syntax highlighting for common file types
include "/usr/share/nano/*.nanorc"

Alt+N toggles line numbers on the fly in current versions; nano 2.9 uses Alt+#.

9. Real troubleshooting examples on your own server

Fix a web server configuration error. Run nginx -t or apachectl configtest, note the file and line it reports, open it with nano +LINE, fix it, test again, and reload only when the test passes.

Change a systemd service safely. Instead of editing a unit file under /usr/lib/systemd/, which a package update can overwrite, create an override:

bash
sudo SYSTEMD_EDITOR=nano systemctl edit myservice
sudo systemctl daemon-reload && sudo systemctl restart myservice

Edit a protected file without running nano as root. sudoedit /etc/hosts opens a temporary copy in your editor and writes it back only when you save.

Update a DNS zone file. If you run your own DNS server, jump to the record, change it, and increase the zone's serial number, or secondary servers will keep the old data. Check the file (for example with named-checkzone) before reloading.

Test before you reload

A typing mistake in SSH, firewall or web server configuration can lock you out or take sites down. Keep your current session open, run the service's config test, and reload rather than restart where possible. With set backup in nanorc, the previous version is kept as filename~.

10. nano on Domain India

For more command-line editing options, read Best ways to edit files over SSH.

How do I open a file at a specific line in nano?

Run nano +LINE followed by the file name, for example nano +120 /etc/nginx/nginx.conf. Add a column with nano +120,15. Inside nano, press Ctrl+_ or Alt+G and type the line number.

How do I search and replace all matches in nano?

Press Ctrl+\, type the text to find, press Enter, type the replacement and press Enter, then press A to replace every match. Alt+R at the prompt switches regular expressions on.

How do I copy and paste a block of text in nano?

Press Alt+A to start marking, move the cursor to select the block, press Alt+6 to copy or Ctrl+K to cut, then move to the new position and press Ctrl+U to paste.

How do I show line numbers in nano permanently?

Add set linenumbers to the file .nanorc in your home directory. You can also start nano with the -l option, or toggle line numbers with Alt+N (Alt+# in nano 2.9).

Does nano have macros?

Yes, from nano 2.9. Press Alt+: to start and stop recording keystrokes, then Alt+; to replay them.

Can I use nano on Domain India shared hosting?

Yes, if jailed SSH is enabled on your account; ask support to enable it. The jailed shell on our cPanel and DirectAdmin servers has nano 2.9.8, and you can edit only your own files, not server configuration.

Ready to work on the command line? Request jailed SSH for your shared hosting with a new support ticket, or get root access on a self-managed VPS.

Need root access to your own server?

A self-managed VPS gives you full root access to edit any configuration file with nano or the editor of your choice.

See VPS plans

Ready when you are

Get DirectAdmin hosting from ₹100/mo + GST

See plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app