- Published on
5 Tips for Avoiding Mistakes While Working with Servers
- Authors
- Name
- Nguyen Phuc Cuong
Have you ever accidentally deployed code to the wrong environment, sending shivers down your spine? Or maybe you've hit Enter too quickly on a rogue command, leaving you scrambling to fix the aftermath? We've all been there, fellow developers. But fear not! Here are some practical tips to streamline your server workflow and minimize those heart-stopping mistakes.
1. Theme Up Your Terminals
Setting up different colored themes for your development, staging, and production environments can act as a visual cue, preventing you from mistakenly running a production command in your dev terminal. Tools like iTerm2 allow you to create profiles for each environment.


For more details, check out this guide on setting up terminal colors.
2. Backup Is Your Best Friend
Before making major server changes, always create backups. This includes your codebase, configuration files, and database data. Use version control systems like Git for code and consider automated backup solutions for other critical data.
"It's better to have it and not need it than need it and not have it."
Here's a simple command to back up files:
cp -ip /yourfile /.backup/yourfile.20240123
3. Be Careful with Special Symbols
When copying commands from online sources, watch out for accidental newlines (\n
) embedded within the command. These can trigger immediate execution, potentially causing issues. Always double-check pasted commands before hitting Enter.
Using a code editor like VS Code can help avoid such problems. It offers features like syntax highlighting and code completion, which can prevent errors caused by misplaced quotation marks ("
, '
) or other special characters.
4. Double-Check Before You Hit Enter
Develop the habit of verifying every command, even routine ones like copying or renaming files. This extra step can prevent accidental data loss. Use terminal commands like ll
or ls -al
to confirm file details before proceeding:
ll file-name
ls -al file-name
Most terminal emulators also offer command history features, allowing you to review previously executed commands easily.
5. Tame the Long SSH Strings
Tired of typing lengthy server IP addresses? Use SSH configuration files to assign friendly aliases to your servers. This allows you to connect with simple commands like ssh production
.
Here's how to set it up by editing the SSH config file located at ~/.ssh/config
:
# Server production
Host production
HostName 18.18x.19x.1xx
User ec2-user
IdentityFile key/server-key.pem
# Staging dev
Host dev
HostName 13.xxx.15x.13x
User ec2-user
IdentityFile key/server-key.pem
Now, you can connect to your servers effortlessly using their aliases.
Thanks for Reading!
I hope these tips help you navigate the server environment more confidently and efficiently. If you have any tips or alternative approaches, feel free to share them in the comments below.