Secure Shell (SSH) provides a secure and encrypted way to access and manage remote servers. One of the most common tasks system administrators and developers perform over SSH is creating and editing files. This article walks you through the basic steps of managing files via SSH, using built-in command-line editors.

Connecting to the Server via SSH

Before you can create or edit a file, you need to establish an SSH connection:

ssh username@your-server-ip
  • username: Your SSH user (e.g., root or admin).

  • your-server-ip: The IP address of your remote server.

If you’re using a custom port, add -p port_number:

ssh -p 2222 username@your-server-ip

Creating a File

To create a new file, you can use one of several commands:

Using touch

touch myfile.txt

This creates an empty file called myfile.txt in the current directory.

Using echo

echo "Initial content" > myfile.txt

This creates a file and adds a line of text.

Editing a File

You can edit files using command-line text editors. Here are the most common options:

nano (Beginner-friendly)

nano myfile.txt
  • Easy to use, with on-screen commands.

  • Use Ctrl + O to save, Ctrl + X to exit.

vi / vim (Advanced users)

vi myfile.txt
  • Press i to enter insert mode.

  • Type your content.

  • Press Esc, then type :wq to save and exit.

cat (Quick edits)

To view or append content:

cat myfile.txt # View
echo "Another line" >> myfile.txt # Append

Changing File Permissions (Optional)

After creating/editing, you may want to update permissions:

chmod 644 myfile.txt

Or change ownership:

chown user:user myfile.txt

Conclusion

Managing files via SSH is a core part of remote server administration. Whether you’re setting up configuration files or logging system data, tools like nano, vi, and touch make it easy to get the job done. Mastering these basics helps you work efficiently on any Linux-based system over SSH.