How do I scp between two remote hosts?

To scp between two remote hosts, you typically need to be logged into one of the hosts and execute the scp command there.

The general format is like this:

scp <user>@<source_host>:<source_file_path> <user>@<destination_host>:<destination_file_path>

Suppose, you are logged into host1, and you want to copy a file from host2 to host3.
First, make sure that the key-based ssh authentication is set up for host2 -> host1 and host1 -> host3. Then, on host1, you can execute:

scp user@host2:/path/to/source/file.txt user@host3:/path/to/destination/

This will copy file.txt from host2 to host3.

Keep in mind this command requires you to have proper SSH access and permissions for both source and destination hosts. If you do not have the necessary authentication set up, the command will ask for the password for each machine.

Set up key-based SSH authentication

To set up key-based SSH authentication, you’ll need to generate a key pair on host1, then copy the public key to host2 and host3. Here’s how you can do it:

  1. Step One — Create the RSA Key Pair on host1:

Open a terminal and run the following command:

ssh-keygen -t rsa

You will be asked to specify the file location and passphrase (optional). If you just press Enter through those prompts, it will create an RSA key pair with default settings.

  1. Step Two — Store the Keys and Passphrase:

When you are prompted to “Enter a file in which to save the key,” you can press Enter. This accepts the default file location.

At the prompt, type a secure passphrase or press enter to proceed without a passphrase.
After completing these steps, your new keys are available in your user home folder ~/.ssh/id_rsa for your private key and ~/.ssh/id_rsa.pub for your public key.

  1. Step Three — Copy the Public Key to host2 and host3:

Next, you’ll copy your public key to your host2 and host3 using the ssh-copy-id command. Like this:

ssh-copy-id user@host2
ssh-copy-id user@host3

Replace user with your username, and host2 or host3 with the IP address or hostname of your second and third machines. You will be prompted for the user password for host2 and host3 to copy the public key.

That’s it! You have set up the key-based ssh authentication. Now you can log into host2 and host3 from host1 without a password:

ssh user@host2

or

ssh user@host3

This method applies to any Linux or Unix system that uses SSH. Please refer to the documentation for Windows servers or any other non-Unix systems. Also note that the user must have ssh and shell access.

Warning: Be careful with your private key (~/.ssh/id_rsa). Don’t share your private key with anyone! In production environments, it’s a common practice to protect private keys with a strong passphrase.

Note: The scp command is not installed by default on some systems. You can install it using your system package manager (like apt, yum, etc.). Alternatively, you can use rsync or sftp depending on the systems and permissions involved.

Important: Remember about data security. Always ensure safe and secure data transfer, especially when dealing with sensitive data. Use encrypted channels for such transfers (which scp does by utilizing SSH). Make sure the user whose credentials are used for the transfer has only the necessary permissions and nothing more.

How do I compile and execute a JDK preview features with Maven?

To compile and execute a JDK preview features with Maven, you need to add in the following configurations in your pom.xml file:

  • Compiler Plugin: The configuration should specify the JDK version and enable the preview features. It should look similar to this:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <release>21</release>
                <compilerArgs>--enable-preview</compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
  • Surefire Plugin: If you’re using the Maven Surefire Plugin to run your tests, you should also enable the preview features there. The configuration may look similar to this:
<build>
    <plugins>
    ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <argLine>--enable-preview</argLine>
            </configuration>
        </plugin>
    </plugins>
</build>

Before building your project, ensure that you have JDK 21-preview installed on your computer, and it’s properly set in JAVA_HOME environment variable or in the IDE settings.

Then use Maven to package or install your project:

mvn clean package
# or
mvn clean install

Please ensure that you have the correct version of maven-compiler-plugin and maven-surefire-plugin that support the JDK 21-preview features. For the project that uses Spring MVC, you should make sure all dependencies are compatible with JDK 21-preview as well.

How do I install Calibri font in Ubuntu?

I need to create a Microsoft Word Mail Merge document in my Java Spring MVC application. But running it in Ubuntu server resulting in a document that missing the default font use in the document, which is the Calibri font. So I need to install the font in Ubuntu to make the document looks as expected.

Here what I need to do to install the font in my Ubuntu box. Starts by updating the repository package list to get latest packages information for upgrades or new package installation.

sudo apt-get update

Then install FontForge in our system. FontForge is a free and open source font editor, but in this case it will help to do the font conversion in the installation script on the upcoming step.

sudo apt-get install fontforge

Install the Microsoft Cabinet file un-packer. This is required for the next script to successfully install the fonts.

sudo apt-get install cabextract

The following script will install Microsoft Vista TrueType Fonts (TTF) in Ubuntu. It includes the following fonts, Calibri, Cambria, Candara, Consolas, Constantia, and Corbel.

wget https://gist.githubusercontent.com/maxwelleite/10774746/raw/ttf-vista-fonts-installer.sh -q -O - | sudo bash

Run the next command to see if the font successfully installed. You will see the Calibri fonts in the result if the fonts successfully installed.

fc-list | grep Calibri

Here are the list of installed Calibri fonts.

/usr/share/fonts/truetype/vista/calibriz.ttf: Calibri:style=Bold Italic
/usr/share/fonts/truetype/vista/calibrii.ttf: Calibri:style=Italic
/usr/share/fonts/truetype/vista/calibrib.ttf: Calibri:style=Bold
/usr/share/fonts/truetype/vista/calibri.ttf: Calibri:style=Regular

How to Install Consolas Font in Mac OS X?

Here are the instructions to install Microsoft Consolas Font on Mac OS X.

  • You need to install brew first.
  • Type-in the following commands.
brew install cabextract
cd ~/Downloads
mkdir Consolas
cd Consolas
curl -LO https://sourceforge.net/projects/mscorefonts2/files/cabs/PowerPointViewer.exe
cabextract PowerPointViewer.exe
cabextract ppviewer.cab
open CONSOLA*.TTF
  • Press Install Font button to install the fonts.

How do I clear the current command line in terminal?

Terminal

You have typed a long line of command in terminal. But now you want to clear or delete the entire line. Deleting each character in the command will take sometime and bored you. So are there any keyboard shortcuts that allow you to do this? Yes there are some hotkeys to the rescue.

Hotkeys Description
CTRL + u Delete the current command.
The deleted command will be stored into a buffer.
CTRL + w Delete a word.
CTRL + c Abort what you are typing.
CTRL + d Delete current character.

Other hotkeys that might help you work faster in the terminal.

Hotkeys Description
CTRL + e Move to the end of line.
CTRL + a Move to the start of line.
CTRL + k Cut text from the cursor to the end of line.
CTRL + y Paste the last cut text or buffer.
CTRL + - Undo.
CTRL + b Backward one character.
CTRL + f Forward one character.
ALT + Backward one word.
ALT + Forward one word.