SSH – creating aliases

On this page
  1. Saving Permanent Aliases
  2. Editing the file
  3. My aliases
  4. Format: alias name=”command”
  5. Detailed listing
  6. Advanced Commands (Functions)
  7. Example: Running PHP Commands via Alias

SSH aliases allow you to define custom shortcuts (keywords) that execute longer or more complex commands in the SSH terminal. This helps speed up repetitive tasks and reduces typing errors.

For example, instead of typing:

ls -la

You can create an alias:

alias lista="ls -la"

After this, typing lista will execute ls -la.

Note: Aliases created this way only work for the current SSH session.

Saving Permanent Aliases

To make aliases persistent, you need to add them to the ~/.bashrc file.

Editing the file

Run:

mcedit ~/.bashrc

Then add your aliases, for example:

My aliases

Format: alias name=”command”

Detailed listing

alias ll="ls -la"

To save changes:

  • Press F2 to save
  • Press F10 to exit editor

Apply changes immediately:

source ~/.bashrc

Advanced Commands (Functions)

Aliases can also execute multiple commands using functions.

Basic structure:

function_name () {
commands
}

Example: create and enter a directory

nkat ()
{
mkdir -p -- "$1" && cd -P -- "$1"
}

Usage:

nkat new_folder

This will:

  • Create a folder
  • Immediately move into it

Explanation:

  • nkat → function name
  • mkdir → creates directory
  • $1 → first argument passed to the function
  • && → runs next command only if previous succeeds

Example: Running PHP Commands via Alias

You can also wrap application commands:

runapp ()
{
php "$1" path_to_application "$2"
}

Example usage:

runapp 7.3 update

This can be used to:

  • Select PHP version
  • Run a tool (like Composer)
  • Pass arguments automatically

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.