error – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Wed, 21 Dec 2022 13:21:35 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 (Resolved) SSH Connection Refused on Ubuntu & Debian https://tecadmin.net/resolved-port-22-connection-refused-on-ubuntu-debian/ https://tecadmin.net/resolved-port-22-connection-refused-on-ubuntu-debian/#respond Fri, 26 Aug 2022 13:23:18 +0000 https://tecadmin.net/?p=31357 The “Connection Refused” error means that the computer is not accepting connection requests to the requested IP address and port. Connection requests may be blocked by a firewall, which is why “Connection refused” is displayed. When a computer receives a connection request from an IP address and port that it wants to connect to, but [...]

The post (Resolved) SSH Connection Refused on Ubuntu & Debian appeared first on TecAdmin.

]]>
The “Connection Refused” error means that the computer is not accepting connection requests to the requested IP address and port. Connection requests may be blocked by a firewall, which is why “Connection refused” is displayed.

When a computer receives a connection request from an IP address and port that it wants to connect to, but the firewall blocks the connection, the “Connection Refused” error message appears. “Connection refused” can be due to a firewall blocking connection requests. In some cases, none of the services are listening on the requested port also causes the “Connection Refused” error.

The Problem:

Today, I installed a new Ubuntu system on my LAN network. I faced an error “Port 22: Connection refused” during the SSH connection to this system. After a bit troubleshoot, I got that there is no SSH server running on the newly installed system.

I got the error message below:

Port 22: Connection Refused Solution
Port 22: Connection refused error

How to Resolve “Port 22: Connection refused” Error

There are the 4 most common reasons behind this error. One or more reasons can cause this issue as listed blow.

  1. SSH Server is not installed
  2. SSH service is not active
  3. SSH service is running on a different port
  4. SSH port is blocked by the firewall

Let’s discuss all the possible solutions one by one.

1. SSH Server is not installed

The OpenSSH is used for SSH service on Debian-based systems. Some of the newly installed systems may not have SSH daemon. Most likely, when you install a new Desktop system, the OpenSSH packages are not included by default.

You can run the following commands to install the ssh service on your system.

sudo apt udpate && sudo apt install openssh-server 

Once the installation is finished, you can connect to your system on port 22. If you are still facing issues, check for other reasons defined below.

2. Check SSH Service is Active and Running

Generally, the SSH service is started automatically after the installation. But might be service is stopped due to some reason. To check the current status of the SSH service, execute:

sudo systemctl status ssh 

If the SSH service is not running or not active, use the below-mentioned commands to enable service on system startup and start service.

sudo systemctl enable ssh 
sudo systemctl start ssh 

Once the service is started successfully, you can connect to your system over ssh. In case, you still face the same error, check for the next possible issue.

3. SSH service is running on a different port

Might be the SSH service is listening on a different port. That is also a best practice for securing servers. You can find out the SSH server port by running the following command.

ss -tulpn | grep ssh 
Check SSH Port
Check ssh port

The above screenshot shows that the SSH service is listening on port 2222. You should connect the remote system with SSH on port 22. We can define a port number with an SSH connection as the below-mentioned command.

ssh -p 2222 root@192.168.1.210 

Hope this will resolve your issue. If still you are facing the same issue, check the below suggestion.

4. SSH port is blocked by the firewall

This is the most common cause that the firewall is blocking the requests.

Now, you need to identify, what firewall are you using. If the remote system is on the cloud hosting, check the security group of that hosting.

On the systems with physical access, can check if UFW or Firewalld is active.

  • Using UFW
  • Check the status of the UFW firewall with the below command:

    sudo ufw status 
    

    If the firewall is in an active state, you can open Port 22 with the below-mentioned command.

    sudo ufw allow 22/tcp 
    
  • Using FirewallD
  • Check if the firewalld daemon is active and running:

    sudo systemctl status firewalld 
    

    If the output shows Active: active (running), then you can open the SSH port by running the following command.

    sudo firewall-cmd --permanent --zone=public --add-port=80/tcp   
    

    Then reload the firewall to apply changes.

    sudo firewall-cmd --reload  
    

Conclusion

In this blog post, we have discussed four possible issues for the error “Port 22: Connection refused”. Also provides the solutions for each issue. Hope this tutorial help to resolve your issue.

If you found any other reason for this issue, please mention it in the comment.

The post (Resolved) SSH Connection Refused on Ubuntu & Debian appeared first on TecAdmin.

]]>
https://tecadmin.net/resolved-port-22-connection-refused-on-ubuntu-debian/feed/ 0
How to Detect and Handle Errors in Your Bash Scripts https://tecadmin.net/execute-specific-command-on-error-in-bash-script/ https://tecadmin.net/execute-specific-command-on-error-in-bash-script/#respond Sat, 30 Jul 2022 21:53:56 +0000 https://tecadmin.net/?p=30831 We can use the trap command to catch the error signal system by the system during script execution. Then you can execute a shell command or call a function. In this way, you can execute your custom script code on an error that occurred in a bash script. This can be helpful to revert any [...]

The post How to Detect and Handle Errors in Your Bash Scripts appeared first on TecAdmin.

]]>
We can use the trap command to catch the error signal system by the system during script execution. Then you can execute a shell command or call a function. In this way, you can execute your custom script code on an error that occurred in a bash script.

This can be helpful to revert any partial changes, close database connections, or email status to the concerned persons, etc. You can use trap commands with `ERR` signals like:

trap 'on_error_function' ERR

When an error is generated in a shell script, it will execute a function named ‘on_error_function’ of your shell script. Instead of calling a function, you can simply run a command as well.

Example: Execute a function on Error in Bash

Let’s understand with an example. Create a sample shell script, and create a function with any name. Then add the trap command with the function for ERR signal. Next, add a simple command that generates an error.

#!/usr/bin/env bash

on_error(){
  echo "Some error occurred"
}

trap 'on_error' ERR

ls ~/dir_not_exists

Execute the above script and you should see the results below:

Output:
ls: cannot access '/home/tecadmin/dir_not_exists': No such file or directory Some error occurred

You can see that the error is trapped and the function on_error() is executed by the bash script.

Example: Execute a command on Error in Bash

Let’s see one more example. Here we will execute a command when any error will occur in the shell script.

#!/usr/bin/env bash

trap 'echo Ohhh no!' ERR

ls ~/dir_not_exists

In the above script, we do not define any separate function. Simply run an echo command on error. Execute the above script and see the results.

Output:
ls: cannot access '/home/tecadmin/dir_not_exists': No such file or directory Ohhh no!

Example: Get the line number of error occurred

You can also find out the line number, where the error occurred in the bash script along with the script name. To do this use the bash inbuilt ‘caller’.

#!/usr/bin/env bash

on_error(){
        echo "Error found in: $(caller)" >&2
}

trap 'on_error' ERR

ls ~/dir_not_exists

Execute the above script and see the results. You will see the script name and the line number, where the error occurred.

Output:
ls: cannot access '/home/tecadmin/dir_not_exists': No such file or directory Error found in: 9 ./script.sh

Conclusion

Thanks for reading this article. Hopefully, this tutorial helps you with better writing of shell scripts by catching the error and taking some action.

Also, remember that the ERR trap catches the runtime errors only. Like if any command returns the non-zero status code. It doesn’t catch the syntax errors, because in the case of syntax error the script fails without running any command.

The post How to Detect and Handle Errors in Your Bash Scripts appeared first on TecAdmin.

]]>
https://tecadmin.net/execute-specific-command-on-error-in-bash-script/feed/ 0
GPG Key Error during MySQL 5.7 Installation https://tecadmin.net/gpg-key-error-during-mysql-5-7-installation/ https://tecadmin.net/gpg-key-error-during-mysql-5-7-installation/#comments Sat, 18 Jun 2022 07:51:41 +0000 https://tecadmin.net/?p=30578 The Problem Today, I have installed MySQL 5.7 on a CentOS 7 Linux system. I used the MySQL official yum repository for the installation. During the installation, I faced the following error message on the screen and the installation failed. Downloading packages: warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-client-5.7.38-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY Retrieving key from [...]

The post GPG Key Error during MySQL 5.7 Installation appeared first on TecAdmin.

]]>
The Problem

Today, I have installed MySQL 5.7 on a CentOS 7 Linux system. I used the MySQL official yum repository for the installation. During the installation, I faced the following error message on the screen and the installation failed.

Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-client-5.7.38-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.


 Failing package is: mysql-community-client-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

The Solution

After a few searches, I found that MySQL has updated its GPG key. The latest GPG key can be installed with the following command.

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 

Hope this blog post helps you to resolve the GPG key issue on your system.

The post GPG Key Error during MySQL 5.7 Installation appeared first on TecAdmin.

]]>
https://tecadmin.net/gpg-key-error-during-mysql-5-7-installation/feed/ 1
(Resolved) zookeeper is not a recognized option – Kafka https://tecadmin.net/resolved-zookeeper-is-not-a-recognized-option-kafka/ https://tecadmin.net/resolved-zookeeper-is-not-a-recognized-option-kafka/#comments Fri, 06 May 2022 07:28:53 +0000 https://tecadmin.net/?p=29877 Problem Recently, I installed Apache Kafka on the Ubuntu system. When tried to run the consumer console script, I found the error message that “zookeeper is not a recognized option”. ./bin/kafka-console-consumer.sh --topic testTopic --zookeeper localhost:9092 zookeeper is not a recognized option Option Description ------ ----------- --bootstrap-server --consumer-property properties in the form key=value to ... ... [...]

The post (Resolved) zookeeper is not a recognized option – Kafka appeared first on TecAdmin.

]]>
Problem

Recently, I installed Apache Kafka on the Ubuntu system. When tried to run the consumer console script, I found the error message that “zookeeper is not a recognized option”.

./bin/kafka-console-consumer.sh --topic testTopic --zookeeper localhost:9092 
zookeeper is not a recognized option
Option                                   Description
------                                   -----------
--bootstrap-server 
--consumer-property                            properties in the form key=value to
...
...

Solution

After searching a bit time, I visited to Apache Kafa QUICKSTART guide. Here I found the solution that Kafka has removed --zookeeper option and replaced it with a new option --bootstrap-server .

So the new command would be like:

./bin/kafka-console-consumer.sh --topic testTopic --bootstrap-server  localhost:9092 

Hope this will help you to resolve the Kafka issue.

The post (Resolved) zookeeper is not a recognized option – Kafka appeared first on TecAdmin.

]]>
https://tecadmin.net/resolved-zookeeper-is-not-a-recognized-option-kafka/feed/ 1
Sendmail User Unknown Error (Resolved) https://tecadmin.net/sendmail-user-unknown-error-resolved/ https://tecadmin.net/sendmail-user-unknown-error-resolved/#comments Fri, 08 Jan 2021 07:55:16 +0000 https://tecadmin.net/?p=24359 Recently, I have faced the below issue with a new Sendmail installation on a Linux system. While sending emails to a specific domain like user@domain.com are showing the error “stat=User unknown“. The issue was happening for a specific domain only. Sending emails to other domain were working properly. The log file entries are looks like [...]

The post Sendmail User Unknown Error (Resolved) appeared first on TecAdmin.

]]>
Recently, I have faced the below issue with a new Sendmail installation on a Linux system. While sending emails to a specific domain like user@domain.com are showing the error “stat=User unknown“.

The issue was happening for a specific domain only. Sending emails to other domain were working properly.

The log file entries are looks like below:

Jan  7 08:36:04 tecadmin sendmail[22497]: 1078a4RD022497: from=www-data, size=679, class=0, nrcpts=1, msgid=, relay=www-data@localhost
Jan  7 08:36:04 tecadmin sendmail[22497]: 1078a4RD022497: to=user@domain.com, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30679, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Jan  7 08:36:04 tecadmin sendmail[22497]: 1078a4RD022497: 1078a4RE022497: DSN: User unknown

Solution:

After troubleshooting the issue, we found that this happens because your domain name matches either your server’s hostname or a setting in Sendmail’s config file. In that case, we can configure Sendmail to force send emails to your actual mail server instead of itself.

Follow the below instructions:

  1. Edit /etc/mail/sendmail.mc and add the following lines at the end:
    sudo vim /etc/mail/sendmail.mc 
    

    Add the following entries:

    define(`MAIL_HUB', `domain.com.')dnl
    define(`LOCAL_RELAY', `domain.com.')dnl
    

    Make sure to change your domain name end with the trailing dot!

  2. Now, run the sendmailconfig command, so that the changes take effect, and restart sendmail just to be 100% sure:
    sudo sendmailconfig 
    

    Press ‘Y’ for all confirmation prompted.

  3. Finally, restart the Sendmail service to apply changes.
    sudo systemctl restart sendmail 
    

All done. Again send an email and the email should be delivered to the actual mailbox.

The post Sendmail User Unknown Error (Resolved) appeared first on TecAdmin.

]]>
https://tecadmin.net/sendmail-user-unknown-error-resolved/feed/ 1
How to Fix ‘/usr/bin/dirmngr’: No such file or directory https://tecadmin.net/fix-dirmngr-no-such-file-or-directory/ https://tecadmin.net/fix-dirmngr-no-such-file-or-directory/#respond Sun, 20 Oct 2019 09:05:29 +0000 https://tecadmin.net/?p=19672 During the importing of the GnuPG key on our Debian system, we faced the following error. This is due to the minimal installation of our Debian servers. This tutorial will help you to fix “‘/usr/bin/dirmngr’: No such file or directory” error. This tutorial will help you to solve this on all Debian based Linux systems. [...]

The post How to Fix ‘/usr/bin/dirmngr’: No such file or directory appeared first on TecAdmin.

]]>
During the importing of the GnuPG key on our Debian system, we faced the following error. This is due to the minimal installation of our Debian servers. This tutorial will help you to fix “‘/usr/bin/dirmngr’: No such file or directory” error. This tutorial will help you to solve this on all Debian based Linux systems.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B

Executing: /tmp/apt-key-gpghome.1uzliCJjyg/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
gpg: connecting dirmngr at '/run/user/0/gnupg/d.9awoasrggmw7i87e3cdkmbgp/S.dirmngr' failed: No such file or directory
gpg: keyserver receive failed: No dirmngr

Solution

You just need to install the dirmngr package on your system. Simply execute the following commands on terminal to install:

sudo apt update
sudo apt install dirmngr --install-recommends

After installing dirmngr package, again tried to import the GnuPG key and successfully imported it to our Debian system.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B

Executing: /tmp/apt-key-gpghome.UbN2VLG9LZ/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
gpg: key 4B7C549A058F8B6B: public key "MongoDB 4.2 Release Signing Key " imported
gpg: Total number processed: 1
gpg:               imported: 1

The post How to Fix ‘/usr/bin/dirmngr’: No such file or directory appeared first on TecAdmin.

]]>
https://tecadmin.net/fix-dirmngr-no-such-file-or-directory/feed/ 0
(Fixed) Laravel – Please Provide a Valid Cache Path https://tecadmin.net/laravel-please-provide-a-valid-cache-path-fixed/ https://tecadmin.net/laravel-please-provide-a-valid-cache-path-fixed/#comments Fri, 12 Jul 2019 11:51:10 +0000 https://tecadmin.net/?p=19233 If you are using Laravel and you see an error message that says “Please provide a valid cache path,” it means that Laravel is unable to write to the specified cache directory. This can be caused by a number of factors, such as incorrect permissions on the cache directory, or a lack of write access [...]

The post (Fixed) Laravel – Please Provide a Valid Cache Path appeared first on TecAdmin.

]]>
If you are using Laravel and you see an error message that says “Please provide a valid cache path,” it means that Laravel is unable to write to the specified cache directory. This can be caused by a number of factors, such as incorrect permissions on the cache directory, or a lack of write access to the directory.

Please provide a valid cache path.

After more debugging and Google it, I found that the storage/framework directory is missing from deployment. Because the .gitignore file has an entry of storage/framework directory to prevent them from adding code to the git repository and this is normal.

Laravel - please provide a valid cache path.

Solution:

To fix this error, you will need to ensure that the cache directory is writable by the user that is running the Laravel application. You can check the permissions on the cache directory by using the `ls -l` command to list the contents of the directory. The permissions should be set to allow the user that is running the Laravel application to write to the directory.

ls -l /path/to/laravel/storage/framework/ 

Check for the available directories under it. It should contain cache, sessions, and views directories and all should be writable by the web server user.

Working Laravel cache directory permissions
Working Laravel cache directory permissions

In case of the directories are missing, Use the following commands to create the required directory.

mkdir -p /path/to/laravel/storage/framework/cache 

Then check for the file permissions. For example, if the user that is running the Laravel application is www-data, the permissions on the cache directory should be set to 775 or 777. You can use the `chmod` command to change the permissions on the cache directory, like this:

chmod -R 777 /path/to/laravel/storage/framework/cache 
chown -R www-data:www-data /path/to/laravel/storage/framework/cache 

Once you have set the correct permissions on the cache directory, you should be able to use Laravel’s cache functionality without any issues. If you continue to see the “Please provide a valid cache path” error

The post (Fixed) Laravel – Please Provide a Valid Cache Path appeared first on TecAdmin.

]]>
https://tecadmin.net/laravel-please-provide-a-valid-cache-path-fixed/feed/ 9
How to Enable PHP errors to Display on Web Browser https://tecadmin.net/enable-php-errors/ https://tecadmin.net/enable-php-errors/#comments Wed, 23 Jan 2019 09:40:44 +0000 https://tecadmin.net/?p=18039 This tutorial will help you to enable PHP errors to display on the web browser. This is helpful for debugging purpose. First of all, enable display_errors parameter in your php.ini configuration file. display_errors = on Then, add the following code to your the application PHP script. For example, add this code to your index.php or [...]

The post How to Enable PHP errors to Display on Web Browser appeared first on TecAdmin.

]]>
This tutorial will help you to enable PHP errors to display on the web browser. This is helpful for debugging purpose.

First of all, enable display_errors parameter in your php.ini configuration file.

display_errors = on

Then, add the following code to your the application PHP script. For example, add this code to your index.php or other default load script.

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Here is a sample index.php with enabled error to display on browser.

Enable PHP Errors

The post How to Enable PHP errors to Display on Web Browser appeared first on TecAdmin.

]]>
https://tecadmin.net/enable-php-errors/feed/ 1
SSH – permissions are too open. https://tecadmin.net/ssh-with-private-key-warning-unprotected-private-key-file/ https://tecadmin.net/ssh-with-private-key-warning-unprotected-private-key-file/#respond Tue, 22 Sep 2015 05:44:47 +0000 https://tecadmin.net/?p=8533 I have launched a new Linux instance in my AWS account and downloaded the private key file. As we all know, AWS only allows default key-based SSH authentication. When I tried to SSH with the downloaded private key file, I got the a warning message Permissions 0644 for ‘server.pem’ are too open and it prompted [...]

The post SSH – permissions are too open. appeared first on TecAdmin.

]]>
I have launched a new Linux instance in my AWS account and downloaded the private key file. As we all know, AWS only allows default key-based SSH authentication. When I tried to SSH with the downloaded private key file, I got the a warning message Permissions 0644 for ‘server.pem’ are too open and it prompted for the password.

In this faq, you will learn to fixe WARNING: UNPROTECTED PRIVATE KEY FILE! error in Linux.

The Problem:

The error looks like the below:

ssh -i server.pem ubuntu@remote-server.com
Output
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for 'server.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. bad permissions: ignore key: server.pem ubuntu@remove-server.com's password:

I was aware of this issue, so I got it fixed easily. If we read the error message carefully, we will understand that there are some issues with the permissions on the server.pem file.

So this tutorial is for our readers to quickly solve this issue without wasting their time. Thanks

The Solution:

As per security policy, the private key file must not be publicly viewable in order to successfully log in to the server using SSH protocol. So you need to change the file permissions to restrict access to the owner only. The owner only required the read permission to use this file during an ssh connection. Change the file permissions with the following command:

chmod 400 server.pem 

Now try to ssh with the same command and same key file.

ssh -i server.pem ubuntu@remote-server.com 

You will be able to ssh properly to the remote server without any error message.

The post SSH – permissions are too open. appeared first on TecAdmin.

]]>
https://tecadmin.net/ssh-with-private-key-warning-unprotected-private-key-file/feed/ 0
The login is invalid – WHM/cPanel https://tecadmin.net/the-login-is-invalid-whm-cpanel/ https://tecadmin.net/the-login-is-invalid-whm-cpanel/#respond Wed, 29 Apr 2015 17:00:48 +0000 https://tecadmin.net/?p=7709 Today I have installed new WHM/cPanel server on an AWS instance. Generally AWS servers are used key based login for ssh users and users don’t have root password. So I have manually reset root password through command line. After installation of cPanel when I tried to login to WHM using web browser I got The [...]

The post The login is invalid – WHM/cPanel appeared first on TecAdmin.

]]>
Today I have installed new WHM/cPanel server on an AWS instance. Generally AWS servers are used key based login for ssh users and users don’t have root password. So I have manually reset root password through command line. After installation of cPanel when I tried to login to WHM using web browser I got The login is invalid error even I was using correct login user and password. I tried the same thing by changing root password 3-4 times but still facing same issue.

Error: The login is invalid

whm-invalid-login

After that I google about this issue and found few solutions in which below solution work for me.

Solution:

This issue is creating due to my IP address was blocked by cphulkd. So I have added my ip to white list using following command. Make sure to change 11.22.33.44 with your actual public ip. To find your public ip visit here.

root@cpanel [~]# /scripts/cphulkdwhitelist 11.22.33.44 

11.22.33.44 has been whitelisted

After that I was able to login successfully using root account in WHM panel.

The post The login is invalid – WHM/cPanel appeared first on TecAdmin.

]]>
https://tecadmin.net/the-login-is-invalid-whm-cpanel/feed/ 0