Disable RPCbind

If your systemd listens on port 111 but you don’t want that, please do the following steps:

  • verify it’s listening on port 111 with netstat or ss:
# ss -tpna|grep 111
LISTEN     0      128          *:111                      *:*                   users:(("systemd",pid=1,fd=39))
LISTEN     0      128         :::111                     :::*                   users:(("systemd",pid=1,fd=38))
  • disable rpcbind:
# systemctl stop rpcbind

# systemctl disable rpcbind

# systemctl mask rpcbind

# systemctl stop rpcbind.socket

# systemctl disable rpcbind.socket

# systemctl status rpcbind
● rpcbind.service
   Loaded: masked (/dev/null; bad)
   Active: inactive (dead) since Sun 2017-12-17 15:31:11 CET; 3min 51s ago
 Main PID: 10920 (code=exited, status=0/SUCCESS)

Dec 13 13:28:35 sys.example.com systemd[1]: Starting RPC bind service...
Dec 13 13:28:35 sys.example.com systemd[1]: Started RPC bind service.
Dec 17 15:31:11 sys.example.com systemd[1]: Stopping RPC bind service...
Dec 17 15:31:11 sys.example.com systemd[1]: Stopped RPC bind service.
  • verify it’s no longer listening:
# ss -tpna|grep 111

CentOS inserting new line of text after another using sed not working

I’m trying to insert a line of text which is;

include /etc/nginx/sites-enabled/*;

On the next line after the words;

for more information.

in my /etc/nginx/nginx.conf using the following command

sudo sed '/for more information.'/a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

But each time i run it, it just returns


Im not very good with this sort of stuff so i was hoping someone could help me out.



Remove the second single-quote. It is superfluous:

sudo sed '/for more information./a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

Also, Because . matches any character and you probably want it to match only a period, escape it like this:

sudo sed '/for more information\./a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

Or this:

sudo sed '/for more information[.]/a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

Search and replace the following in vi

Hi I want to replace the occurrence of [x] with [] in vi editor

I have used the following command


and it gives me [[]], how to update my command so that I get desired result.


You can replace:

  • It once (the first occurrence on the current line) with: :s/\[x\]/[]/
  • It everywhere on the current line with :s/\[x\]/[]/g
  • The first occurence on every line with :%s/\[x\]/[]/
  • It everywhere :%s/\[x\]/[]/g

(Obviously you must make sure you are in command mode, use the esc-key for this)

iterate over a map and export vars

this script prints out the right values but it looks like my export statement isn’t correct:

declare -A ENVMAP=( [foo]=bar [baz]=quux [corge]=grault )
for i in "${!ENVMAP[@]}"
  echo "key  : $i"
  echo "value: ${ENVMAP[$i]}"
  export "$i"="${ENVMAP[$i]}"

The value gets printed correctly so the map works but the vars aren’t getting exported. Whats wrong with my export statement?


In case you want to have these vars permanently in your user’s system you could add them into your current user’s DOT/BASH profile too, few steps are as follows:

I– Go to current user’s directory by doing normal cd.

II– Then list all files including hidden ones by doing either ls -la or ls -lhtr.

III– Now either add these export commands in your BASH profile(in case you are on Linux/bash) or you could create your own .profile too(only one will be picked up at a time).

IV– Once you saved it then use source .profile or source .bash_profile or . ./.profile or . /.bash_profile.

Please try these and let me know if these helps you.

Adding a shell command inside/inline of a systemd service file

I am running the gunicorn server as a service via systemd, Here is the sample service file:

Description=Gunicorn NGINX

ExecStart=/usr/local/bin/gunicorn --workers 8 --threads 8 --backlog 100 --bind -m 777 abc:app


I want now to replace the number near --workers and --threads by number of cores using the shell command so that it will dynamically pick the number of cores

nproc --all

Can someone help me how to do this


You can explicitly invoke a shell to get shell parsing.

ExecStart=/bin/bash -c '/usr/local/bin/gunicorn --workers "$(nproc --all)" --threads "$(nproc --all)" --backlog 100 --bind -m 777 abc:app'

ansible: execute a role with condition

You can execute a role in ansible with condition as follows:


# Installation and configuration of nodejs

- hosts: http
  user: "test"
  become: yes
  become_method: sudo
  connection: ssh
     - { role: http, when: "ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7'" }

python: uninstall python 2.7 install via source

To completely remove python you can execute:

rm -f /usr/local/bin/python2.7
rm -f /usr/local/bin/pip2.7
rm -f /usr/local/bin/pydoc
rm -rf /usr/local/bin/include/python2.7
rm -f /usr/local/lib/libpython2.7.a
rm -rf /usr/local/lib/python2.7

You might also have to do

rm -f /usr/local/share/man/python2.7.1
rm -rf /usr/local/lib/pkgconfig
rm -f /usr/local/bin/idle
rm -f /usr/local/bin/easy_install-2.7