When you try to use the xclip command over the ssh-based session to copy and paste data, you will get the following message on screen:
Error: Can't open display: (null)
Here is how to fix this error by editing the ssh client and OpenSSH (SSHD server) configuration file.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to fix “Error: Can’t open display: (null)” with ssh and xclip command in headless mode appeared first on nixCraft.
A long time ago, I wrote a script or config file that included BASE64 encoded string like "Le_PreHook='__ACME_BASE64__START_L3Jvb3QvYmluL2xlL2N5YmVyY2l0aS5iaXovcHJlX2JlZm9yZV9vYnRhaW5pbmdfYW55X2NlcnRpZmljYXRlcy5zaA==__ACME_BASE64__END_". So I wanted to know what this string was to update my config script. Here is how to decode BASE64 in Linux or Unix-like systems.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to decode BASE64 string in Linux and Unix appeared first on nixCraft.
I have a valuable tip for you on extracting the filename and extension in Bash when using Linux, macOS, FreeBSD, or Unix-like systems. It's quick and easy to follow.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to get and extract filename extension in Bash appeared first on nixCraft.
Let us see how to check for ssh connectivity in a shell script running under macOS, FreeBSD, or Linux/Unix desktop using BatchMode=yes and ConnectTimeout=$VALUE options. This simple trick helps write a wrapper script that does other things, such as making a backup or running external command agents such as Salt or Ansible to do other tasks.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to check for ssh connectivity in a shell script appeared first on nixCraft.
While working on the bash shell script wrapper, I needed to ensure that I only passed an integer in the Bash script under Linux and Unix-like systems. Here is how to check if a number is an integer in Bash Linux or Unix script or at the command-line interface (CLI)
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post Bash see if an input number is an integer or not appeared first on nixCraft.
I have a tutorial that explains the basics of the SSH client configuration file and some of the most common configuration options for Linux and Unix developers or sysadmin. In this quick tip, I will explain how and why you sometimes need to ignore or exclude the ssh client config file under Linux, Unix, *BSD and macOS.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to tell ssh client to ignore ssh config file appeared first on nixCraft.
Sometimes you need to use the ls command on your Linux or Unix machine and match the pattern, interpreting upper- and lowercase letters as the same. In other words, I tell ls to find and list files regardless of their case insensitive. For instance, I am going to tell ls command command to ignore the case so that it can match files such as:
$ ls *service*.pdf
SERVICE.pdf
DELL-Service-M6700.pdf
hp-printer-Service-Manual.pdf
In this quick tip, I explain how to match case insensitive patterns with the ls command on your Linux, macOS, *BSD and Unix-like system.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to run ls command case insensitive mode on Linux/Unix appeared first on nixCraft.
As you may know, email spoofing allows attackers to pose as someone else to gain illegal profit. For example, I only use webmaster@cyberciti.biz for communication, but someone might create a spoofed-up email, say info@opensourceflare.com, to trick someone. This is called email spoofing with fake headers as follow:
Date: Thu, 24 Oct 2021 12:46:10 From: nixCraft <info@opensourceflare.com> Reply-To: info@opensourceflare-email.com To: <my@personal_gmail_com>
Correct headers are often not checked by receiving email servers, and my@personal_gmail_com may think the email is from me. Here is the thing I don't use opensourceflare.com for email communication at all. So how do I prevent illegitimate email traffic on my domain? In this tutorial, I will explain how to configure DNS settings that tell receiving email servers this domain is not configured for emailing purposes and the attacker maliciously sending email on my behalf.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post DNS settings to avoid email spoofing and phishing for unused domain appeared first on nixCraft.
Today I will talk about a common problem faced by many Linux or Unix sysadmins and developers. Typically modern apps and security devices heavily depend upon APIs and lists that feed data in JSON format. For example, a list of spamming or VPN CIDRs or a good list of verified bots' IP CIDRs is in JSON format. If they accept JSON format, you can take this list and upload it to your router or WAF. Unfortunately, not all devices accept JSON format. Hence, we can take JSON format and convert it to CSV format per our needs.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to convert JSON to CSV using Linux / Unix shell appeared first on nixCraft.
Like every other solo developer and sysadmin, I do stuff using ssh. Some stuff is automated using scripts, and others require ssh login. For example, one of my scripts logs into my Linux and FreeBSD server using public ssh keys and does a particular type of work for me. I have a dedicated user account for that purpose called autovivek on Raspberry PI 4 for Ansible and custom script automation. Here is how it works:
{rpi4:~}$ ssh autovivek@192.168.2.17 /path/to/taks1
In other cases, it sends scripts and then executes them on the remote server named 192.168.2.17. Sounds good, right? So, when I need to make backups and other tasks, I lock down the autovivek user account on the server so that it will not modify data on disks. For example, here is how to lock down a user account:
{linux-server:~}$ sudo usermod -L -e 1 autovivek
## OR ##
{freebsd-server:~}$ sudo pw lock -n autovivek
However, I soon discovered that a user named autovivek can still log into the server and make changes despite being locked down on both Linux and FreeBSD servers.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post A cautionary tale about locking Linux & FreeBSD user accounts appeared first on nixCraft.
So I have this specific use case where I get data in a comma-separated values (CSV) file. I pick up the company name, address, telephone, email, and some other data from that file. Once data is collected, I create a final pdf using a simple script. Unfortunately, data comes with unwanted leading and trailing white spaces in each field. So my final pdf file gets messed up because of those white space. Let us see how to trim leading and trailing white space for a string in Bash running on Linux or Unix machines.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to trim leading and trailing white space in bash appeared first on nixCraft.
Another day I wrote about setting up ssh public key password-less authentication for FreeBSD server version 12/13 with an optional 2FA hardware USB key (FIDO 2) for additional protection. However, FIDO2 and key type ecdsa-sk and ed25519-sk are not supported by the OpenSSH client and server version shipped with FreeBSD 12 or 13. But, fear not, we can safely upgrade the OpenSSH version using ports collection. This page explains how to install and configure the latest portable version of the OpenSSH client and server on FreeBSD 13.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to install and upgrade OpenSSH server on FreeBSD appeared first on nixCraft.
SSH is an essential tool for login into the FreeBSD Unix box. Without SSH, you cannot manage a remote server easily. Furthermore, SSH means secure shell, and it is a replacement for insecure protocols such as telnet. This page explains how to configure and set up ssh key-based password-less authentication on a FreeBSD server or workstation.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to set up ssh public key password-less on FreeBSD appeared first on nixCraft.
This page explains setting up a static IP address on the FreeBSD Unix system using the command-line options.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to configure static IP Address on FreeBSD appeared first on nixCraft.
I have multiple versions of PHP installed on my development VM. I am migrating all my projects from PHP 7.x to 8.x and testing it. However, this leads to specific problems. For example, my production Linux container is on PHP 7.4.26, while the development VM is on PHP 8.1. So they don't match and causes problem even in the dev environment because I have 7.x and 8.x. Here is how to tell the composer to use different PHP versions per project requirements.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to tell and force Composer to use a specific PHP version such as 7.x or 8.x appeared first on nixCraft.
The xz command on Linux, macOS, *BSD, and Unix-like systems offer excellent compression. It will outperform zip and other formats when we use xz with tar for maximum reduction in size. For instance, I compressed a directory having 37M size using both xz and zip. The zip file size was 31M, while the xz file was 16M after compression. Pretty impressive, isn't it? Let us see how to compress the whole directory using xz and tar.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to compress the whole directory using xz and tar appeared first on nixCraft.
This quick tutorial explains How to check the SHA1 hash of a file on Linux, FreeBSD, and Unix-like systems using the sha1sum or sha1 command.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to check SHA1 hash on Linux, FreeBSD and Unix appeared first on nixCraft.
First, there is no fsck command for ZFS, which Linux and Unix use for file system repair. However, ZFS comes with a scrub option. This subcommand is a root-initiated dynamic consistency check. It runs in the background on a mounted live filesystem. Hence, we use the zpool scrub command for ZFS storage and test file system integrity. Let us see how to check ZFS File system storage pool on Linux, FreeBSD or Unix-like systems using the command-line option.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to check ZFS File system storage pool on Linux/Unix appeared first on nixCraft.
Most of us use love and use the jq command. It works on Linux or Unix-like systems to extract data from JSON documents. Recently I found htmlq, which is like jq and written in Rust lang. Imagine being able to sed or grep for HTML data. We can search, slice, and filter HTML data with htmlq. Let us see how to install and use this handy tool on Linux or Unix and play with HTML data.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to use htmlq to extract content from HTML files on Linux, macOS or FreeBSD appeared first on nixCraft.
All supported versions of FreeBSD are affected by various security bugs that need to be applied ASAP. For example, a memory corruption bug exists in the bhyve hypervisor. Another overwrite the stack of ggatec and potentially execute arbitrary code. There are two issues fixed for OpenSSL in this security advisory too. Let us see what and how to fix these security vulnerabilities on FreeBSD.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post FreeBSD bhyve, OpenSSL, GEOM & libfetch security fixes released appeared first on nixCraft.
At a certain point, I needed to change the VLAN IP address such as 172.0.0.2 with 172.0.0.1 for ease of use. As you know, Linux and Unix-like operating system stores all IP addresses and config in plain text files. This page explains my little adventure where I had to find and find and replace ALL IP addresses with a new one on Linux.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to find and replace ALL IP addresses with a new one appeared first on nixCraft.
Sometimes we need to evaluate multiple when conditions in Ansible playbooks. Let us see how to define multiple when conditions in Ansible for a single task.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to define multiple when conditions in Ansible appeared first on nixCraft.
In Linux, how do I copy and transfer files remotely between two Linux machines? What command do I need to use to transfer files between Unix/macOS and Linux computers securely?
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to copy and transfer files remotely on Linux using scp and rsync appeared first on nixCraft.
We can easily convert all Linux man pages to HTML, text, or pdf format. To display online manual documentation pages in terminal on Linux, macOS, *BSD, and Unix-like systems, we use the man command. However, some man pages are long and might be hard to search when using less or most as a pager. Hence, we can convert them to HTML format and skimmed them in a web browser such as Firefox.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to convert man page to HTML on Linux and Unix appeared first on nixCraft.
Let us say you want to repeat a character such as '-' OR '=' multiple times while writing bash script. Please note that I needed a quick script to work on Linux, macOS, and FreeBSD server to repeat a string/character n times. One simple way to to repeat a string or character n times is simple use the echo command/printf command as follows:
echo '------------------------------------'
printf '%s\n' '------------------------------------'
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to repeat a character ‘n’ times in Bash appeared first on nixCraft.
Did you know? You can turn off the banner in Linux or Unix using a particular file. When you log in using ssh or other methods, you will find tons of information on the screen. Here is how my FreeBSD home server login looks:
Default motd with my hardware and other info
The first one is /etc/motd, and the second is the output of neofetch called from ~/.profile file. And my Ubuntu Linux box showing stuff too when I login using the ssh command:
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post Quick Tip: Turn off the login banner in Linux or Unix .hushlogin file appeared first on nixCraft.
We use the df command to find total disk space and available space on a Linux / Unix file system. Let us see how to use the df command to view the amount of free space left on your Linux, macOS, *BSD and Unix file system. We will also explain how to automate disk space monitoring and send an email alert or push notification to your mobile device.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post How to use df command in Linux / Unix {with examples} appeared first on nixCraft.
Michael Lucas is a famous IT book author. Perhaps best know for FreeBSD, OpenBSD, and Unix book series. He worked as a system administrator for many years and has now become a full-time book writer. Lately, I did a quick Q and A with Michael about his journey as a professional book author and his daily workflow for writing books.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post Interview with Michael Lucas *BSD, Unix, IT and other books author appeared first on nixCraft.
The FreeBSD project released FreeBSD version 13. The new version comes with updated software and features for a wild variety of architectures. The latest release provides performance improvements and better support for FreeBSD. One can benefit greatly using an upgraded version of FreeBSD. Let us see what's new and quickly update FreeBSD 12 to 13 using the CLI.
Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit
The post FreeBSD 13 released: Here is how to upgrade FreeBSD 12 to 13 appeared first on nixCraft.
Even if you do not use the curl command daily, the chances are high that you are still using curl and don't know. IoT and tons of other services on the Internet depend upon libcurl for network operations. Daniel Stenberg is a Swedish software developer, recipient of the Polhem Prize 2017, on cURL. Recently I did a quick Q and A with Daniel about starting the curl project and his daily workflow.
The post Interview with curl creator and Swedish software developer Daniel Stenberg appeared first on nixCraft.
How can I check if a file does not exist in a Bash script?
The post How to check if file does not exist in Bash appeared first on nixCraft.
All supported versions of FreeBSD are affected by various security bugs that need to be applied ASAP. If the process is privileged, it may escape jail and gain full access to the FreeBSD system. Similarly, when using Xen, a malicious or buggy frontend driver may be able to cause resource leaks. Let us see what and how to fix these security vulnerabilities on FreeBSD.
The post FreeBSD jail, xen, and .pam_login_access security fixes released appeared first on nixCraft.
Despite some severe bugs in sudo, it remains the defacto tool to gain root shell or run command as another user on Linux, macOS, and Unix-like systems. The sudo command allows the system administrator to grant an individual user access to unprivileged commands. For instance, I can give developers the ability to restart the Apache webserver or PHP/Python process on a Linux server. Let us see how to remind developers and unprivileged users about the power of sudo for fun and profit. In this quick tip, I will show you how to add some spice to your sudo session with a lecture file on Linux or Unix.
The post Adding spice to your sudo session with a lecture file on Linux or Unix appeared first on nixCraft.
How do I remove all the carriage returns \r (^M) from a file in Unix using the command-line options?
The post How to remove carriage return in Linux or Unix appeared first on nixCraft.
I need to restrict access to /app/ directory on Nginx. How do I set up password protect a directory with Nginx .htpasswd authentication on Linux or Unix-like systems?
The post How to password protect directory with Nginx .htpasswd authentication appeared first on nixCraft.
I need to set a bash environment variable called PURGEIMAGE and take specific actions in my script. For example, if PURGEIMAGE set, then purge images from CDN else just URL. I am going to call my script as PURGEIMAGE=yes ./purgecache.sh url1 url2. So how do I know if a bash variable set at the CLI and used in my bash script running on Linux or Unix-like systems?
The post How to check if bash variable defined in script appeared first on nixCraft.
Homebrew is an essential package manager for developers, sysadmins, and power users on macOS. Homebrew allows us to install the latest and updated version of popular applications, packages, and developer tools. Homebrew is the painless way to install required packages on your Mac. For instance, we can install PostgreSQL, Python, PHP, Bash, Nginx, Apache, and much more using brew command. This page explains how to install and use Homebrew on the macOS system to get missing packages. Homebrew installs the apps you need that Apple didn't include in their base operating system or app store.
The post How to install Homebrew on macOS to use the brew package manager appeared first on nixCraft.
I have two columns (fields) in my text file. I am trying to insert '|
FOO This is a description
BAR Another description for bar
TEXT Another description for TEXT
So I ran awk '{ print $1 "|"; $1=""; print}' input > output but print command is adding a new line:
FOO|
This is a description
BAR|
Another description for bar
TEXT|
Another description for TEXT
Is there any way to tell awk not to print a newline and create the file? Here is what I want so that I can create final HTML table based upon '|'
FOO|This is a description
BAR|Another description for bar
TEXT|Another description for TEXT
The post How to force awk not to print a newline appeared first on nixCraft.
How do I install, set up and configure a FreeBSD 12 jail with VNET on ZFS? How can I create FreeBSD 12 VNET jail with /etc/jail.conf to run OpenVPN, Apache, Wireguard and other Internet-facing services securely on my BSD box?
The post How to set up FreeBSD 12 VNET jail with ZFS appeared first on nixCraft.
A text editor is an essential tool for both developers and sysadmin, especially when dealing with text based sessions. We use a text editor to create, edit, and update text. A text editor is used for many things. Some use them to write documents. Some people write code and others use it to edit Linux and Unix configuration files locally or remote servers running in the cloud. Let us see the top 6 text editors for Linux, macOS, and Unix command-line users/developers.
The post Top 6 awesome text editors for Linux and Unix command-line users/developers appeared first on nixCraft.
I need to define a bash variable called failed and set the value to False. When my script is called from a cron job, specific tasks might fail, and then I need to flip failed to True. Based upon $failed, I need to send an email alert that my cron job has failed. So how can I declare and use Boolean variables in a shell script running on a Linux server?
The post How to declare Boolean variables in bash and use them in a shell script appeared first on nixCraft.
How do I create an admin user in MySQL? How can I set up and create a superuser account in a MySQL server running on Linux or Unix-like systems? Can you provide a quick guide about making a superuser with root-like access to the MySQL or MariaDB databases?
The post How to create MySQL admin user (superuser) account appeared first on nixCraft.
How do I check the TLS/SSL certificate expiration date from my Linux or Unix shell prompt? How can I find the TLS certificate expiry date from Linux and Unix shell scripts?
The post How to check TLS/SSL certificate expiration date from command-line appeared first on nixCraft.
I am using the FreeBSD system. How do I install Speedtest-cli on a FreeBSD Unix system for checking the Internet speed?
The post How To Install Speedtest-cli On a FreeBSD To Check Internet Speed appeared first on nixCraft.
Want to display a message or banner before OpenSSH (SSHD server) authentication? Try this simple tip to show the banner or ASCII logo on your Linux or Unix system.
The post Quick tip: Display banner/message before OpenSSH authentication appeared first on nixCraft.
Are you looking to send a temporary email right from your Linux or Unix terminal? Look no further. Try tmpmail command-line utility that allows you to generate a temporary email address for receiving emails. Underneath the script uses 1secmail's API to receive the emails.
The post tmpmail – A temporary email right from Linux / Unix terminal appeared first on nixCraft.
How do I use the ssh-agent command for non-interactive authentication on Linux and Unix-like systems such as macOS or FreeBSD desktop? My private key is protected with a passphrase or password. So I need have to enter the passphrase to use the ssh private key for authentication multiple times. How can I tell ssh ask the passphrase one time only?
The post How to use ssh-agent for authentication on Linux / Unix appeared first on nixCraft.
Linux is a free and open-source kernel developed by Linus Torvalds, a Unix-like operating system clone. XKCD comic has a long tradition for including humorous geeky cartoons. In this post, I pick my favorite XKCD comics for Linux and Unix fans.
The post Top 15 XKCD comics for Linux and Unix fans appeared first on nixCraft.
How do I write the output into the file in Linux bash shell? Can you explain I/O redirection for both bash and POSIX shell to write data to the file under Unix or Linux?
The post How to write the output into the file in Linux appeared first on nixCraft.