Prerequisites
Before using nano, make sure you have:
- SSH access to your VPS
- Write permissions for the file you want to edit
💡 nano is the easiest text editor for beginners and is pre-installed on most Linux distributions.
Step 1: Open a File with Nano
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22Open a file (creates new file if doesn't exist):
nano filename.txtOpen with sudo (for system files):
sudo nano /etc/nginx/nginx.confStep 2: Basic Navigation
Once in nano:
- Arrow keys - Move cursor
- Page Up/Page Down - Scroll by page
- Home - Beginning of line
- End - End of line
Step 3: Editing Text
Just start typing to insert text.
Delete characters:
- Backspace - Delete character before cursor
- Delete - Delete character at cursor
Cut and paste:
- Ctrl+K - Cut current line
- Ctrl+U - Paste cut line
- Alt+6 - Copy line (then Ctrl+U to paste)
Step 4: Save and Exit
Ctrl+O - Save file (write out)
Press Enter to confirm filename.
Ctrl+X - Exit nano
If you haven't saved, nano will ask: "Save modified buffer?"
- Y - Yes, save then exit
- N - No, exit without saving
- Ctrl+C - Cancel, return to editing
Useful Nano Shortcuts
| Shortcut | Action |
|---|---|
| Ctrl+G | Help (lists all commands) |
| Ctrl+W | Search for text |
| Ctrl+ | Search and replace |
| Ctrl+C | Show cursor position |
| Ctrl+_ | Go to line number |
| Ctrl+T | Check spelling |
| Alt+U | Undo |
| Alt+E | Redo |
| Alt+A | Set mark (start selection) |
| Alt+6 | Copy selected text |
Working with Multiple Files
Open multiple files:
nano file1.txt file2.txt
Switch between files:
- Alt+, - Previous file
- Alt+. - Next file
Enable Line Numbers
To enable line numbers, press Alt+N (toggle on/off).
To permanently enable, create or edit ~/.nanorc:
echo "set linenumbers" >> ~/.nanorc
Syntax Highlighting
Nano includes syntax highlighting for many file types.
Enable by default:
echo "include /usr/share/nano/*.nanorc" >> ~/.nanorc
Common Editing Examples
Edit SSH configuration:
sudo nano /etc/ssh/sshd_config
Edit hosts file:
sudo nano /etc/hosts
Edit PHP configuration:
sudo nano /etc/php/8.1/cli/php.ini
Edit crontab:
crontab -e
Recover Unsaved Files
If your SSH session disconnects while editing:
Nano saves backups as filename.save
Check for saved files:
ls -la | grep .save
Recover:
nano filename.save
Create .nanorc Configuration
# ~/.nanorc - Nano configuration
set tabsize 4
set tabstospaces
set autoindent
set linenumbers
set nowrap
set smooth
set backups
set backupdir ~/.nano_backups
Create backup directory:
mkdir -p ~/.nano_backups
Search and Replace Example
- Press Ctrl+
- Enter search text (e.g., "olddomain.com")
- Enter replacement text (e.g., "newdomain.com")
- Press A to replace all, or Y/N for each match
✅ You can now edit files using the nano text editor on your Hostxpeed VPS.