20 Most Commonly Used SSH Commands in Linux Illustrated with Examples

20 Most Commonly Used SSH Commands in Linux Illustrated with Examples

09:11, 31.07.2023

A Linux command refers to a program or utility that is executed on the command line interface, accepting lines of text as input and processing them as instructions for the computer. While graphical user interfaces (GUIs) provide a visual representation, they ultimately rely on underlying command-line programs to perform actions. Flags are used to pass options to commands, with the "-h" flag commonly used to access the help page. Arguments or parameters provide input to commands, typically in the form of file paths or other text entered in the terminal. Flags are denoted by hyphens or double hyphens, while the execution of arguments depends on their order within the command.

SSH (Secure Shell) commands in Linux are used to establish secure remote connections to other systems or servers. SSH provides a secure encrypted channel for communication, allowing users to log in to remote machines, execute commands, transfer files, and perform various administrative tasks.

In this tutorial, we will discuss 20 fundamental SSH commands that are important to know. By mastering these commands, you’ll know the basic of Linux administration.

'ls' command

The 'ls' command in Linux is a useful tool for listing files and directories in a specific directory. It provides valuable information about file permissions, ownership, and other attributes. By default, the 'ls' command arranges the output in alphabetical order.

The 'ls' command offers various options to enhance functionality. For example, '-l' displays detailed information, '-a' shows hidden files, '-h' presents sizes in a human-readable format, '-t' sorts by modification time, and '-R' enables recursive listing.

By utilizing these options, you can customize the output of the 'ls' command according to your needs and gain a deeper understanding of the files and directories present in your Linux system.

The 'alias' command

The 'alias' command in Linux allows you to create temporary shortcuts or aliases for longer commands. When you create an alias, you define a word or phrase that represents a series of commands.

For instance, you can set up an alias for the 'ls' command to include the '--color' flag without typing it every time. The alias would look like this:

alias ls="ls --color=auto"

In this example, the 'alias' command is used with the syntax alias NAME="VALUE". The value, which represents the series of commands, needs to be enclosed in quotes.

To view all the aliases defined in your current shell session, you can simply run the 'alias' command without any arguments. This will display a list of all the aliases you have set up.

The 'pwd' command

The 'pwd' command in Linux serves a simple yet essential purpose: printing the current directory which is working now in the terminal. While your terminal prompt often shows the current directory, the 'pwd' command can be handy in situations where it's not readily visible. Moreover, it's valuable when scripting, as it helps locate the directory where a script is saved. 

The 'touch' command

The 'touch' command in SSH is utilized to create a new file. The syntax is straightforward: 'touch [file name]'. For instance, to create a .txt file named "myfile", you would enter 'touch myfile.txt'. The file extension can be customized according to your preference, and it's also possible to create a file without any extension. 

The 'cd' command

The 'cd' (Change Directory) command allows you to navigate between directories. Simply type 'cd' followed by the name of the directory to enter it. For example, 'cd home' takes you to the home directory. You can also specify the full path of a directory to navigate to a specific location. To go back one level, use "..", and you can go back further by adding more ".." separated by a forward slash ("/").

The 'mkdir' command 

The 'mkdir' command is used in the terminal to create directories. The basic syntax is 'mkdir' followed by the desired directory name. 

The 'rm' command

The 'rm' command in Linux is used to remove or delete files and directories. It is a powerful command that allows you to delete files and directories permanently, so it should be used with caution.

Here are some commonly used options with the 'rm' command:

'-r': Recursively removes directories and their contents.

'-f': Forces the removal without prompting for confirmation.

'-i': Prompts for confirmation before deleting each file.

'-v': Displays detailed information about the files being removed.

'-rf': A combination of '-r' and '-f' options, used to forcefully remove directories and their contents without prompting for confirmation.

The 'cat' command

The 'cat' command in Linux supports the use of wildcard characters to display the contents of multiple files. By using the "*" wildcard character, you can list the content of all files in the current directory. 

The 'chmod' command

The 'chmod' command in Linux is used to modify file permissions or modes. It allows you to change the read, write, and execute permissions of a file.

The basic permissions that can be assigned to a file are:

'r' (read)

'w' (write)

'x' (execute)

The 'man' command

The 'man' command in Linux displays detailed information and documentation about various commands. To view the manual page for a specific command, use:

man [command]

For example, to view the manual page for the 'mkdir' command, enter:

man mkdir

To access the manual page for the 'man' command itself, use:

man man

These manual pages provide comprehensive information about command usage, options, and examples.

The 'exit' command

The 'exit' command in Linux is used to terminate a shell session and close the associated terminal. When you execute the 'exit' command, it effectively ends the current session and exits the shell environment. 

The 'shutdown' command

The 'shutdown' command in Linux is used to power off, halt, or reboot the machine. By default, it initiates a power-off process with a one-minute delay. To immediately power off the computer, you can use the following command:

shutdown now

The 'clear' command

The 'clear' command in Linux is used to clear the terminal display, removing all previous output and commands from the screen. By typing 'clear' and pressing enter, you can quickly and easily reset the terminal, providing a clean and empty interface for your use. 

The 'zip' ‘unzip’ command

The 'zip' command compresses files into a zip archive, while 'unzip' extracts files from a zip archive.

To create a zip archive:

zip archive.zip file1.txt file2.txt

To extract files from a zip archive:

unzip archive.zip

Additional options and functionalities are available for advanced usage.

The 'clear' command

The 'clear' command is used to clear the contents of the terminal display, providing a clean slate for new commands and output. It removes all the previous commands and output from the terminal window, giving you a fresh and empty screen to work with. 

The 'echo' command

The 'echo' command in Linux displays text or variables on the terminal. It is commonly used to output messages or variables for debugging or informing users. Simply typing 'echo' followed by the desired text or variable will print it on the terminal. It is a useful command for displaying information during script execution or interacting with the user. 

The 'service' command

The 'service' command in Linux is used for managing system services. It provides functionality to start, stop, or restart services running on the system. This command is commonly used for controlling daemons and background processes. By specifying the service name and the desired action (start, stop, restart), you can effectively manage the services on your Linux system using the 'service' command. 

The 'ps' command

The 'ps' command in Linux allows you to view the processes running within your current shell session. It provides valuable information about the programs you are running, such as the process ID, TTY (TeleTYpewriter), time, and command name. By using the 'ps' command, you can gain insights into the running processes and monitor their status and resource usage. 

The 'tar' command

The 'tar' command in Linux is a versatile utility used for creating, extracting, and compressing files and directories. It is commonly employed for backups and working with archives. 

The 'kill' command

When you encounter an unresponsive program that cannot be closed through normal means, the 'kill' command comes to the rescue. It allows you to send a TERM or kill signal to a process, effectively terminating it.

To kill a process, you can specify either the PID (process ID) or the binary name of the program:

kill 533494
kill firefox

Exercise caution when using this command, as it carries the risk of unintentionally terminating your work.

In conclusion, acquiring familiarity with these 20 fundamental SSH commands in Linux will equip you with the essential skills to effectively administer remote servers and accomplish a range of tasks securely. These commands offer robust functionalities for remote access, file transfer, authentication, tunneling, and more. Take the opportunity to experiment with these commands and unlock their potential to elevate your Linux SSH experience.

views 7m, 18s
views 2
Share

Was this article helpful to you?

VPS popular offers

Other articles on this topic

cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.