Tuesday, October 12, 2021

13 Linux Terminal Shortcuts Every Power Linux User Must Know

 https://linuxhandbook.com/linux-shortcuts

 

Use Linux command line like a pro by mastering these Linux terminal shortcuts and increase your productivity. It's a must for any power Linux user.
Table of Contents

You know what sets apart a pro user from a regular user? Mastery over the keyboard shortcuts.

Alright! That’s not the only thing but it is undoubtedly a factor.

Shortcuts help you to be more productive and efficient with whatever tool you use. Just think about it. If someone holds the mouse all the way down to copy entire text instead of Ctrl+A, how would you feel about it?

Linux terminal is not an exception. There are certain Linux terminal shortcuts that every user must know and practice.

Trust me; once you master these shortcuts, you’ll notice how good you are with using the Linux command line.

Must Know Linux Shortcuts

Linux Terminal Shortcuts

I would like to mention that some of these shortcuts may depend upon the Shell you are using. Bash is the most popular shell, so the list is focused on Bash. If you want, you may call it Bash shortcut list as well.

Do note that I have used the capital letters in the keyboard shortcuts but this does NOT mean that you have to press the shift key while using these shortcuts.

1. Tab

This is the Linux shortcut you cannot live without. It will save you so much time in the Linux command line.

Just start typing a command, filename, directory name or even command options and hit the tab key. It will either automatically complete what you were typing or it will show all the possible results for you.

If you could only remember one shortcut, this would be the chosen one.

2. Ctrl + C

These are the keys you should press in order to break out of a command or process on a terminal. This will stop a running program immediately.

If you want to stop using a program running in the foreground, just press this key combination.

3. Ctrl + Z

This shortcut will send a running program in the background. Normally, you can achieve this before running the program using the & option but if you forgot to do that, use this key combination.

4. Ctrl + D

This keyboard shortcut will log you out of the current terminal. If you are using an SSH connection, it will be closed. If you are using a terminal directly, the application will be closed immediately.

Consider it equivalent to the ‘exit’ command.

5. Ctrl + L

How do you clear your terminal screen? I guess using the clear command.

Instead of writing C-L-E-A-R, you can simply use Ctrl+L to clear the terminal. Handy, isn’t it?

6. Ctrl + A

This shortcut will move the cursor to the beginning of the line.

Suppose you typed a long command or path in the terminal and you want to go to the beginning of it, using the arrow key to move the cursor will take plenty of time. Do note that you cannot use the mouse to move the cursor to the beginning of the line.

This is where Ctrl+A saves the day.

7. Ctrl + E

This shortcut is sort of opposite to Ctrl+A. Ctrl+A sends the cursor to the beginning of the line whereas Ctrl+E moves the cursor to the end of the line.

Note: If you have the Home and End keys on your keyboard, you can also use them. Home is equivalent to Ctrl +A and End is equivalent to Ctrl + E.

8. Ctrl + U

Typed a wrong command? Instead of using the backspace to discard the current command, use Ctrl+U shortcut in the Linux terminal. This shortcut erases everything from the current cursor position to the beginning of the line.

9. Ctrl + K

This one is similar to the Ctrl+U shortcut. The only difference is that instead of the beginning of the line, it erases everything from the current cursor position to the end of the line.

10. Ctrl + W

You just learned about erasing text till the beginning and the end of the line. But what if you just need to delete a single word? Use the Ctrl+W shortcut.

Using Ctrl+W shortcut, you can erase the word preceding to the cursor position. If the cursor is on a word itself, it will erase all letters from the cursor position to the beginning of the word.

The best way to use it to move the cursor to the next space after the targetted word and then use the Ctrl+W keyboard shortcut.

11. Ctrl + Y

This will paste the erased text that you saw with Ctrl + W, Ctrl + U and Ctrl + K shortcuts. Comes handy in case you erased wrong text or if you need to use the erased text someplace else.

12. Ctrl + P

You can use this shortcut to view the previous command. You can press it repeatedly to keep on going back in the command history. In a lot of terminals, the same can be achieved with PgUp key.

13. Ctrl + N

You can use this shortcut in conjugation with Ctrl+P. Ctrl+N displays the next command. If you are viewing previous commands with Ctrl+P, you can use Ctrl+N to navigate back and forth. Many terminals have this shortcut mapped to the PgDn key.

Bonus shortcut: Ctrl + R to search in command history

You typed some command but cannot remember what it was exactly? Meet Ctrl + R.

This keyboard shortcut allows you to perform a search in your command history. Just press Ctrl+R and start typing. It will show the last command that matches the string you typed. Note that the typed string could be anywhere in the command. How cool is that?

Reverse search in command history in Linux

If you want to see more commands for the same string, just keep pressing Ctrl + R.

You can press enter to run the command selected or press Esc to come out of the search with the last search result.

Try it and be amazed.

What’s your favorite Linux terminal shortcut?

If you would like to learn a few more Linux terminal tricks, you may watch this video to unearth hidden command line gems:

I have shared my favorite terminal shortcuts. What are some of your favorite Linux shortcuts? If you have one (or more), why not share it with the rest of us in the comment section?

SSLH – Share A Same Port For HTTPS And SSH

 https://ostechnix.com/sslh-share-port-https-ssh

 In this brief tutorial, we will see what is SSLH, how to install SSLH and how to configure SSLH to share a same port for https, and ssh in Linux and Unix-like operating systems.

What is SSLH?

Some Internet service providers and corporate companies might have blocked most of the ports, and allowed only a few specific ports such as port 80 and 443 to tighten their security.

In such cases, we have no choice, but use a same port for multiple programs, say the HTTPS Port 443, which is rarely blocked. Here is where SSLH, a SSL/SSH multiplexer, comes in help.

SSLH will listen for incoming connections on a port 443. To put this more simply, SSLH allows us  to run several programs or services on port 443 on a Linux system. So, you can use both SSL and SSH using a same port at the same time.

If you ever been in a situation where most ports are blocked by the firewalls, you can use SSLH to access your remote server.

Install SSLH in Linux

SSLH is packaged for most Linux distributions, so you can install it using the default package managers.

On Debian, Ubuntu, Linux Mint and Pop OS, run:

$ sudo apt install sslh

While installing SSLH, you will prompted whether you want to run sslh as a service from inetd, or as a standalone server.

Each choice has its own benefits. With only a few connection per day, it is probably better to run sslh from inetd in order to save resources.

On the other hand, with many connections, sslh should run as a standalone server to avoid spawning a new process for each incoming connection.

install sslh
Install sslh

On Arch Linux and derivatives like Antergos, Manjaro Linux, install it using Pacman as shown below.

$ sudo pacman -S sslh

On RHEL, CentOS, AlmaLinux and Rocky Linux, you need to add EPEL repository and then install SSLH as shown below.

$ sudo dnf install epel-release
$ sudo dnf install sslh

On Fedora:

$ sudo dnf install sslh

If it is not available on default repositories, you can manually compile and install SSLH as described here.

Configure Apache or Nginx webservers

As you already know, Apache and Nginx webservers will listen on all network interfaces (i.e 0.0.0.0:443) by default. We need to change this setting to tell the webserver to listen on the localhost interface only (i.e. 127.0.0.1:443 or localhost:443).

To do so, edit the webserver (nginx or apache) configuration file and find the following line:

listen 443 ssl;

And, change it to:

listen 127.0.0.1:443 ssl;

If you’re using Virutalhosts in Apache, make sure you have changed that it too.

VirtualHost 127.0.0.1:443

Save and close the config files. Do not restart the services. We haven't finished yet.

Configure SSLH

Once you have made the webservers to listen on local interface only, edit SSLH config file:

$ sudo vi /etc/default/sslh

Find the following line:

Run=no

And, change it to:

Run=yes

Then, scroll a little bit down and modify the following line to allow SSLH to listen on port 443 on all available interfaces (Eg. 0.0.0.0:443).

DAEMON_OPTS="--user sslh --listen 0.0.0.0:443 --ssh 127.0.0.1:22 --ssl 127.0.0.1:443 --pidfile /var/run/sslh/sslh.pid"

Where,

  • --user sslh : Requires to run under this specified username.
  • --listen 0.0.0.0:443 : SSLH is listening on port 443 on all available interfaces.
  • --sshs 127.0.0.1:22 : Route SSH traffic to port 22 on the localhost.
  • --ssl 127.0.0.1:443 : Route HTTPS/SSL traffic to port 443 on the localhost.

Save and close the file.

Finally, enable and start sslh service to update the changes.

$ sudo systemctl enable sslh
$ sudo systemctl start sslh

Testing

Check if the SSLH daemon is listening to 443.

$ ps -ef | grep sslh 
sslh 2746 1 0 15:51 ? 00:00:00 /usr/sbin/sslh --foreground --user sslh --listen 0.0.0.0 443 --ssh 127.0.0.1 22 --ssl 127.0.0.1 443 --pidfile /var/run/sslh/sslh.pid
sslh 2747 2746 0 15:51 ? 00:00:00 /usr/sbin/sslh --foreground --user sslh --listen 0.0.0.0 443 --ssh 127.0.0.1 22 --ssl 127.0.0.1 443 --pidfile /var/run/sslh/sslh.pid
sk 2754 1432 0 15:51 pts/0 00:00:00 grep --color=auto sslh

Now, you can access your remote server via SSH using port 443:

$ ssh -p 443 sk@192.168.225.50

Sample output:

sk@192.168.225.50's password: 
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-55-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

System information as of Wed Aug 14 13:11:04 IST 2019

System load: 0.23 Processes: 101
Usage of /: 53.5% of 19.56GB Users logged in: 0
Memory usage: 9% IP address for enp0s3: 192.168.225.50
Swap usage: 0% IP address for enp0s8: 192.168.225.51

* Keen to learn Istio? It's included in the single-package MicroK8s.

https://snapcraft.io/microk8s

61 packages can be updated.
22 updates are security updates.


Last login: Wed Aug 14 13:10:33 2019 from 127.0.0.1
Access remote systems via SSH using port 443
Access remote systems via SSH using port 443

See? I can now be able to access the remote server via SSH even if the default SSH port 22 is blocked. As you see in the above example, I have used the https port 443 for SSH connection. Also, we can use the same port 443 for openVPN connections too.

I tested SSLH on my Ubuntu 18.04 LTS server and it worked just fine as described above. I tested SSLH in a protected local area network, so I am not aware of the security issues. If you're using it in production, let us know the advantages and disadvantages of using SSLH in the comment section below.

For more details, check the official GitHub page given below.

Difference between ext2, ext3 and ext4

 https://kerneltalks.com/disk-management/difference-between-ext2-ext3-and-ext4

 List of differences between ext2, ext3, and ext 4 Linux file systems. One of the Linux interview questions answered in this article!

Comparison : ext2 vs ext3 vs ext4

This is another Linux interview question. What is the difference between ext2, ext3, and ext4 file systems? Or Explain Linux file system ext2 vs ext3 vs ext4? In this article we will walk through these differences and lastly I will present you all of them in tabular format so that they are easy to quickly read during your preparations.

Let’s see each file system’s features and lastly their comparison with other file systems.

EXT2 file system

  • It’s a second extended file system that was created to overcome limitations of the EXT file system.
  • Introduced in 1993 by Remy Card. It was the first commercial-grade filesystem for Linux
  • Does not supports Journaling
  • Fit for SD cards & USB drives since it has high performance and low writes (as journaling is not available). USB and SD storage are limited with write cycles hence its best fit for them.
  • Limits: Individual file size 16GB to 2TB. File system size 2TB to 32TB.

Limits are calculated based on block size used.  Block size varies from 1KB to 8KB. For example,  If 1KB block size is used max file size can go up to 16GB and for 8KB it’s 2TB. Middle range sizes being 2KB and 4KB which has file size limits of 256GB & 2TB (not mentioned in above limits) respectively. The same applies to the File system size limits defined above.

EXT3 file system

  • It’s third extended file system was created to overcome limitations of the EXT2 file system.
  • Introduced in 2001 by Stephen Tweedie. It was the most common filesystem in any Linux distro.
  • Supports Journaling
  • Journaling keeps track of file changes which helps in fast recovery and reduce chances of data loss in case of a system crash
  • Limits: Individual file size 16GB to 2TB. File system size 4TB to 32TB.
  • Upgrading FS from ext2 to ext3 is an online process without downtime.

EXT4 file system

  • It’s the fourth extended file system that was created to overcome limitations of the EXT3 file system.
  • Introduced in 2008 by a team of developers. Its most the latest filesystem in ext family.
  • Supports Journaling
  • Lots of new features introduced. Extents, Backward compatibility, Persistent pre-allocation, Delayed allocation, Unlimited number of subdirectories, Journal checksum, Faster FS check, Transparent encryption.
  • Limits: Individual file size 16GB to 16TB. File system size up to 1EB.
  • Upgrading FS not needed. Due to backward compatibility, ext2, ext3 can be directly mounted as ext4.

All above points can be formatted in tabular format as below :

ParameterEXT2EXT3EXT4
Introduced year

199320012008
Developed by

Remy Card Stephen Tweedie Team of developers
Journaling Not available Available Available
Individual file size

16GB to 2TB 16GB to 2TB 16GB to 16TB
File system size

2TB to 32TB 4TB to 32TB up to 1EB
Upgrade Can be done online to EXT3. Can be mounted as EXT4. No upgrade needed Can be mounted as EXT4. No upgrade needed NA