List of basic SSH commands

Once you’ve logged in to your VPS server using a Secure Shell (SSH), there are many commands available to manage and monitor its resources.

Here are some basic SSH commands you can use to manage the server with the command line.

Create a new file

Use the touch command to create a new file on the server. If the file already exists, the command will update the file’s timestamp.


Edit a file

Launch a text editor with the nano command to make changes to files on your server.

nanoRemove a File or Directory

The rm command is used to remove one or more files or folders from the server.

  • rm filename – remove a file from the server.
  • rm -r directoryname/ – remove a directory and its files from the server.


Create a new directory

Create a new directory on your server using the mkdir command.

  • mkdir foldername – create a new directory called foldername.
  • mkdir -p foldername – create a new directory called foldername, even if the directory already exists.


Change the working directory

Navigate your server’s filesystem using the cd command.

  • cd /path/to/your/directorychange the current working directory to the nominated path. Note that the first / indicates the path is relative to the root directory. If you do not use /, you’re indicating that the path is relative to the current working directory.
  • cd .. – navigate to the parent directory of the current working directory.
  • cd ../.. – navigate up two levels in the directory structure.
  • cd ~ – navigate to the user’s home directory.


Find the current working directory

To find out your current working directory, use the pwd command, which will return the current working directory path.


Display a directory listing

Use the ls command to view a list of contents for a directory.

  • ls – list the contents of a directory.
  • ls -1 – list the directory contents with a single entry per line.
  • ls -l – list the directory contents with full details.
  • ls – lh – list the directory contents with file sizes in a human-readable format.
  • ls -ld – display directory information.
  • ls – lt – list the contents of a directory based on the last modified time.


Change file or directory permissions

The chmod command is used to change read/write permissions for nominated files or directories.

  • chmod options permissions filename – change permissions for filename based on the parameters listed in options.
  • chmod u+x filename – give execute permission for the user.
  • chmod 0744 filename give read, write, and execute permissions for the owner and read permission for groups and others.
  • chmod –r – change file permissions recursively through the directory and its subdirectories.

Permissions can be defined using alphanumeric characters or digits.

  • u – user
  • g – group
  • o – other
  • r – read
  • w – write
  • x – execute

If you need help with your HostPapa account, please open a support ticket from your dashboard.

Related Articles