Bash


Unable to negotiate with IP port 22: no matching host key type found. Their offer: ssh-rsa

Secure Shell (SSH) is a cryptographic network protocol that is commonly used for secure data communication, remote command-line login, and other network services. The SSH command is used to remotely connect to a server or device and execute commands on that device. In this blog post, we will explain the following SSH command and when the extra parameters are needed.

ssh -p 22 -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa user@host;

Breakdown of the SSH command

  • ssh: The command to initiate a Secure Shell connection to a remote host.
  • -p 22: The -p option specifies the port number that SSH should use to connect to the remote host. In this case, the port number is 22, which is the default SSH port number.
  • -o HostKeyAlgorithms=+ssh-rsa: The -o option allows the user to set SSH options. In this case, the option HostKeyAlgorithms specifies the key exchange algorithm that should be used for the connection. The +ssh-rsa parameter adds the ssh-rsa algorithm to the list of acceptable algorithms.
  • -o PubkeyAcceptedKeyTypes=+ssh-rsa: Similar to the previous parameter, this option specifies the type of public key that will be accepted for authentication purposes. The +ssh-rsa parameter adds the ssh-rsa key type to the list of acceptable key types.
  • user@host: Specifies the username and hostname of the remote machine to connect to.

When are the extra parameters needed?

The extra parameters in this SSH command are used to specify the key exchange and authentication algorithms that are acceptable for the SSH connection. This is important because older, less secure algorithms can be vulnerable to attacks. By specifying only the more secure algorithms, you can help ensure that your connection is as secure as possible.

The specific parameters used in this command are not always necessary, but they can be useful in certain situations. For example, if you are connecting to an older SSH server that uses weaker encryption algorithms, you may want to specify only the stronger algorithms that are supported by both the server and your client. Similarly, if you are connecting to a server that requires a specific type of public key for authentication, you can specify that key type using the PubkeyAcceptedKeyTypes option.

In general, it’s a good idea to use the most secure algorithms that are supported by both your client and the remote server. This can help ensure that your connection is as secure as possible and minimize the risk of unauthorized access or data breaches.

In conclusion, the SSH command is a powerful tool for remotely connecting to and managing servers and devices. By understanding the different parameters and options available, you can customize your SSH connections to meet your specific needs and ensure that your connections are as secure as possible.


Splitting a zip file (or any file) into smaller parts

In this post, we will explain the following commands:

  1. zip Original.zip Original/
  2. split -b 5M -d Original.zip Parts.zip.
  3. cat Parts.zip* > Final.zip
  4. unzip Final.zip -d Final

These commands are commonly used in Linux/Unix systems and can be very helpful when working with large files or transferring files over a network.

Command 1: zip Original.zip Original/

The zip command is used to compress files and create a compressed archive. In this command, we are compressing the directory named Original and creating an archive named Original.zip. The -r option is used to recursively include all files and directories inside the Original directory in the archive.

Command 2: split -b 5M -d Original.zip Parts.zip.

The split command is used to split a large file into smaller files. In this command, we are splitting the file Original.zip into smaller files with a size of 5 MB each. The -b option specifies the size of each split file, and the -d option is used to create numeric suffixes for the split files. The Parts.zip is the prefix for the split files.

Command 3: cat Parts.zip* > Final.zip

The cat command is used to concatenate files and print the output to the standard output. In this command, we are concatenating all the split files (which have the prefix Parts.zip) into a single file named Final.zip. The * is a wildcard character that matches any file with the specified prefix.

Command 4: unzip Final.zip -d Final

The unzip command is used to extract files from a compressed archive. In this command, we extract the files from the archive Final.zip and store them in a directory named Final. The -d option is used to specify the destination directory for the extracted files.

In conclusion, these commands can be beneficial when working with large files or transferring files over a network. By using the zip and split commands, we can compress and split large files into smaller ones, making them easier to transfer. Then, using the cat command, we can concatenate the split files into a single file. Finally, we can use the unzip command to extract the files from the compressed archive.


Remove Disabled Snaps.

LANG=C snap list --all | awk '/disabled/{print $1" --revision "$3}' | xargs -rn3 sudo snap remove;

Let us break down the command for you:

  1. LANG=C sets the language to English (C locale), which can be helpful to ensure consistent behavior across different systems with different default languages. We used this to make sure that the word disabled will appear for disabled snaps and not some other translation.
  2. snap list --all lists all installed snaps (i.e., packages) along with their details. The output of this command is piped to the following command.
  3. awk '/disabled/{print $1" --revision "$3}' searches for lines in the output that contain the word “disabled” and prints the first field (i.e., the name of the snap) followed by the string “–revision” and the third field (i.e., the revision number). This output is piped to the next command.
  4. xargs -rn3 sudo snap remove takes groups of three arguments from the input and runs the command snap remove with those arguments. In this case, the first argument is the name of the disabled snap; the second argument is the string “–revision”, and the third argument is the revision number. This will remove all disabled snaps and their associated revisions.

So, in summary, the command searches for all disabled snaps on the system, extracts their name and revision number and then removes them using the snap remove command. This is a very useful command to free up some space without losing data or functionality.


Linux: Delete all files that are older than X days

The command find /data/ -type f -mtime +15 -exec rm -f '{}' \; is used to search and delete all the files in the “/data/” directory that have a modification time of more than 15 days old. The following is an explanation of each part of the command:

  1. “find /data/” – This specifies the directory that the search will start from; in this case, it’s the “/data/” directory.
  2. “-type f” – This option specifies that the search should be limited to files, not directories.
  3. “-mtime +15” – This option specifies that the files should be older than 15 days based on the modification time. The “+” sign indicates that we are looking for files older than 15 days.
  4. “-exec rm -f ‘{}’ \;” – This option is used to execute a command on the files found. The command “rm -f ‘{}'” is used to delete the files and the “{}” is a placeholder for the files that are found. The “” at the end of the line is used to escape the semicolon and avoid a syntax error.

The “find /data/ -type f -ctime +15 -exec rm -f ‘{}’ \;” command is similar to the above command, but it searches for files based on their creation time instead of modification time. The “ctime” option specifies that the search should be based on the file creation time instead of the modification time.

In conclusion, both commands are used to delete files in the “/data/” directory that are older than 15 days. Still, the difference is that the first command searches for files based on their modification time, while the second command searches for files based on their creation time.