Tag: Bash

Unblock IP From fail2ban SSH

Okay, Ive done this sometimes where I typed in my password hastily and ended entering it incorrectly mutiple times which results to my IP being ban by fail2ban. To unban your IP you need to either wait for the ban time you set to expire or if you cant you will need to access your server using a different IP address.

Once you have gained access to your server type this in:

iptables -L -n

Search for the line where you IP is. It should be below the line of:

Chain fail2ban-ssh (1 references)

If its there then your IP is still banned from using SSH. To remove it type:

iptables -D fail2ban-SSH -s [your-ip] -j DROP

Change “[your-ip]” to your actual IP. Now check again the iptables and the entry for your IP is should now be gone and this means that you are now unban from fail2ban-ssh.

Auto Enter Password For sudo Command

Normally using sudo will request the user a password after executing it but sometimes we might need to run a command with sudo from a script(bash script) or from a program. To auto enter a password for a script that will execute a sudo command you will need to do it like this in your script:

echo [password] | sudo -S echo "Sudo with auto enter of password"

Just replace the “[password]” with your actual password. Notice that we have “-S” as the option we pass for the sudo command. This option enables sudo to read the password from stdin where we have echoed our password.

Just an opinion but if you find yourself needing to auto enter a password in sudo command then maybe you should consider running it as a root user instead.

© 2017 James Baltar

Theme by Anders NorenUp ↑