Home » Articles posted by Scriptiee

Changing email password via command line – Plesk

Easily accomplished by running:

$ /usr/local/psa/bin/mail -u [email protected] -passwd NEWPASSWORD

Mounting system in recovery mode

Needed to mount a system in a recovery mode to be able to chroot into it and run updates to attempt to fix it.
Steps required were:

$ mkdir /oldsystem
$ mount /dev/sdb1 /oldsystem
$ mount --bind /dev /oldsystem/dev
$ mount -t proc none /oldsystem/proc
$ mount -t sysfs none /oldsystem/sys
$ chroot /oldsystem

You can replace ‘/oldsystem’ with the path of your liking really.

Have fun fixing stuff 😀

EDIT: Now it ended being a i686 kernel, my recovery was a 64bit therefore yum update was out of question. Way around it was changing the $basearch in the yum.repos.d files. Quick sed command below will do exactly that:

$ sed -i 's|$basearch|i386|g' /etc/yum.repos.d/CentOS-*

Scanning range of ip’s for open ports

Simple scan for open ports on an IP range:

$ nmap

Getting more info from the scan:

$ nmap -sV -vv -PN

Use responsibly 😉

How to sudo echo/cat things

Wanted to ‘cat’ a content of one file to be appended to another which had no permissions for my user, however, I had ‘sudo’ permissions. Basically failed miserably at it, then I figured it might be something to do with the ‘tee’ I knew about from vim.

Tried a

$ man tee

Which in the end lead to this:

$ cat ~/somefile | sudo tee -a /path/to/newfile

And boom! worked a charm, though dumped the content of the file to stout as well. Making it:

$ cat ~/somefile | sudo tee -a /path/to/newfile >/dev/null

solves that.

It’s one of those little brain teasers trying to figure out 😀

SH module for python

For python3 on arch to install python modules installer:

$ sudo pacman -S pip

To install the module:

$ pip install sh

then in python shell/script:

import sh

Then you can use it as follow:

sh.ls("-l", "/home/user")

You can as well iterate over it, for example:

for line in sh.grep("something", "/home/user/somefile"):

Connect to wireless network via the command line

First generate the wpa.conf that will include your network information:

$ wpa_passphrase SSID_NAME PASSPHRASE > wpa.conf

then test the connection to the network:

$ wpa_supplicant -D wext -i IFACE_NAME -c wpa.conf

If that completes successfully, kill with ctrl+c and re-run adding -B option

Then configure the interface, can be done using dhclient if a dhcp server is available on the network

$ dhclient IFACE_NAME

Blocking bots via .htaccess file

Needed to do that the other day as the server load has spiked to 80+

RewriteEngine On
RewriteBase /
SetEnvIfNoCase User-Agent 'bingbot/2.0' bad_agent
Deny from env=bad_agent


SetEnvIfNoCase User-Agent '$BOTNAME' bad_agent

before the “Deny” line for every bot you want to block

Reverse SSH connection

So I have installed Linux for a friend of mine, which he was happy with. However as he’s not the most tech savvy as soon as he encountered an issue (installing flash) he straight away contacted me about it. Trying to explain to him how to do it was like talking to a monkey about real estate, same thing goes to attempting to get him to open an ssh port on his firewall so I could log in.

After a little brain storming I figured that since SSH supports Dynamic port forwarding it definitely have a solution of some sort for me. After reading the ssh manual page the -R option sounded like something I was looking for.

Quick test between my local machine and my cloud server resulted in a success.

Here’s how:

Lets call my PC Machine A and his Machine B.

I created him a user on my system and got him got him to run this on his box:

$ ssh -R 2222:localhost:22 [email protected]

This connected him to my machine A and forwarded the local 2222 port to the port 22 on his machine B.

Then it was just a matter of me running the following:

$ ssh localhost -p 2222

There you go, access to his machine without pulling my hair trying to explain stuff to him! win!

Dynamic port forwarding (SOCKS proxy)

Was in a pickle as needed to access something from a specific IP range. Had an SSH access to the box on that range therefore decided to use dynamic port forwarding. With the command bellow I forced ssh to dynamically forward port 8080 on the machine A to port 22 on the machine B.

$ ssh -D 8080 [email protected]

Then in Firefox under Preferences > Advanced > Network > Settings, I have chose “Manual Proxy Configuration”. In the SOCKS host typed ‘localhost’ and in Port field ‘8080’ (omitting the quotes).

Click Ok and voilà, google what is my IP and the machine B’s IP was displayed, now I could access the range restricted content.

See the list of software installed on your Debian|Ubuntu

To see the list of the packages installed on your system running Debian|Ubuntu just run:

$ dpkg --get-selections
acpi install
acpi-support-base install
acpid install
adduser install
analog install
apache2 install
apache2-doc install
apache2-mpm-prefork install
apache2-utils install
apache2.2-bin install
apache2.2-common install

If you are looking for specific package you can pipe the output to grep, for example:

$ dpkg --get-selections | grep nmap
nmap install

You can as well locate the files that belong to the package by running:

$ dpkg -L nmap

To see the version of the package that is installed/available:

$ dpkg --list nmap

This will give you:

| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                              Version               Architecture          Description
ii  nmap                              6.00-0.3              amd64                 The Network Mapper