- Technical difficulty: ★★☆☆☆
Oftentimes when running and configuring your own server, you will need to edit files. This can be done through SSH by using a text editor. The most common text editors are nano, vi or vim, and emacs.
Common Text Editors
Nano
Nano is the most beginner-friendly text editor available on most Unix-like systems. It's simple, intuitive, and displays keyboard shortcuts at the bottom of the screen.
Basic Nano Commands
- Open a file:
nano filename - Save:
Ctrl+O - Exit:
Ctrl+X - Cut text:
Ctrl+K - Paste text:
Ctrl+U - Search:
Ctrl+W
Vim/Vi
Vim is a powerful, modal text editor with a steeper learning curve than Nano. It's extremely powerful once you learn it, and is available on virtually all Unix-like systems.
Basic Vim Commands
- Open a file:
vim filename - Enter insert mode:
i - Exit insert mode:
Esc - Save:
:w(in normal mode) - Exit:
:q(in normal mode) - Save and exit:
:wq(in normal mode) - Force exit without saving:
:q!(in normal mode)
Emacs
Emacs is another powerful text editor with extensive customization options. It's not as universally available as Nano or Vim, but it's worth knowing about.
How to Choose a Text Editor
- For beginners: Start with Nano. It's straightforward and shows the commands at the bottom of the screen.
- For power users: Vim or Emacs offer more features and efficiency once you've learned them.
- For system administrators: Learning Vim is often beneficial as it's available on almost all systems by default.
Resources for Learning
Nano Resources
Vi/Vim Resources
- Vim Hero - Interactive Vim tutorial
- FreeCodeCamp Vim tutorial
- Vim Adventures - Learn Vim while playing a game
Emacs Resources
Practical Example
Let's say you need to edit the SSH configuration file on your server. Here's how you would do it with Nano:
- Connect to your server via SSH
- Run:
sudo nano /etc/ssh/sshd_config - Make your changes
- Press
Ctrl+Oto save - Press
Enterto confirm the filename - Press
Ctrl+Xto exit
The same task with Vim would look like:
- Connect to your server via SSH
- Run:
sudo vim /etc/ssh/sshd_config - Press
ito enter insert mode - Make your changes
- Press
Escto exit insert mode - Type
:wqand pressEnterto save and exit
Remember that practice makes perfect. The more you use these text editors, the more comfortable you'll become with them.