Sudo copy files as root

To allow user01 to copy any files as root from /from/directory/ to /to/directory/ add the following to /etc/sudors file:

user01 ALL = NOPASSWD: /bin/cp /from/directory/* /to/directory/

And this one is for the multi commands:

user01 ALL = NOPASSWD: /bin/cp /from/directory/* /to/directory/, /bin/rm -rv /to/directory/*, /bin/ls -la /to/direcotry/*

Boot Single User Mode – Resetting forgotten root user account password in RHEL/CentOS 7

As soon as the boot process starts, press ESC to bring up the GRUB boot prompt. You may need to turn the system off from the control panel and then back on to reach the GRUB boot prompt. You will see a GRUB boot prompt – press “e” to edit the first boot option. Find the kernel line linux16 or linuxefi or linux (Each menuentry block that represents an installed Linux kernel contains linux on 64-bit IBM POWER Series, linux16 on x86_64 BIOS-based systems, and linuxefi on UEFI-based systems. Then the initrd directives followed by the path to the kernel and the initramfs image respectively) and add init=/bin/sh at the end of the line and then press CTRL-X to boot.
System will boot and you will see the root prompt. Type mount -rw -o remount / and then passwd to change the root password and then touch /.autorelabel and then exec /sbin/init

In short:
init=/bin/sh – In case of VMWare like KVM or VirtualBox use rb.break instead of inti=/bin/sh
# mount -o remount,rw /
# passwd root
[Enter New Password]
[Re-enter New Password]
# touch /.autorelabel
# exec /sbin/init

It should look like this one:
2: linux16 /vmlinuz-3.10.0-229.7.2.e17.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rhgb quiet LANG=en_IE.UTF-8 systemd.debug init=/bin/sh
3: initrd16 /initramfs-3.10-0-229.7.2.el7.x86_64.img

OpenVPN in OpenVZ/VServer

# Allow OpenVPN
iptables -A INPUT -p udp -m state --state NEW -m udp --dport 1194 -j ACCEPT
iptables -A FORWARD -s -j ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -t nat -A POSTROUTING -s -o venet0:0 -j MASQUERADE
# in OpenVZ/VServers you may need the following instead the lane above
iptables -t nat -A POSTROUTING -s -j SNAT --to-source

OpenVPN and OpenVZ tun issue.

After the upgrade Debian 7 to Debian 8 on OpenVZ platform on OVH the OpenVPN service stopped working. The problem was that the “TUN” device was missing, so the command below will temporary fix this problem.

root# mkdir -p /dev/net
root# mknod /dev/net/tun c 10 200
root# chmod 600 /dev/net/tun

Also you can add this to a script at start up.

Send a file as a mail attachment using mail command.

The simplest way to send a file as a mail attachment is shown by the following examples:

# uuencode snoopy1.jpeg snoopy1.jpeg | mail

If user uses a current mail reader like Mozilla, Netscape Messenger or Microsoft Exchange, she/he will see a mail containing just one file attachment: the file “snoopy1.jpeg”.

This way we can include text, too:

# (cat mailtext; uuencode snoopy1.jpeg snoopy1.jpeg) | mail

The file called “snoopy1.jpeg” again appears twice on the uuencode command line: the first time to specify the input file name, the second time for the remote extraction file name.


echo -e "text in line1 ntext in line2"| mail -s "Subject of an e-mail" -r "User1<>" -a "/tmp/"

Vi delete commands – reference

A lot of times all people need is a quick reference, so I’ll start with a reference of vi/vim delete commands:

x – delete current character
dw – delete current word
dd – delete current line
5dd – delete five lines

d$ – delete to end of line
d0 – delete to beginning of line

delete to beginning of file

delete to end of file

Block an IP address with null routes or with iptables on a Linux.

You can drop as IP address using the iptables command:

iptables -A INPUT -s -j DROP
iptables -A OUTPUT -d -j DROP

However, you can use route or ip command to a null route unwanted traffic. A null route is a network route or kernel routing table entry that goes nowhere.

route add gw lo

or reject 😉

route add -host reject

Also we can drop entire subnet

route add -net gw lo

To delete an IP address or entire subnet from a null route use the following command:

route del gw lo


route del -net gw lo

The df command not showing correct values.

A common programming technique is to create a temporary file and immediately unlink() it. This leaves the file (and its space) available for the duration of the program but automatically causes its removal when the program using it terminates. One advantage is that no epilog (cleanup) code is necessary to write. To determine if you have a process holding an unlinked file open, do:

lsof -a +L1 /ebstest01db


lsof +D /ebstest01db +L1

Look for any files with an NLINK value of zero (0). These would be files with a zero link count that will vanish when the last process terminates. The SIZE/OFFSET column will offer the character size of the file in question.

sles02:/ # lsof -a +L1 /ebstest01db
oracle 9605 ebstest01 256u REG 8,33 40255488 0 3678213 /oradata/data_old/cntrl01.dbf (deleted)
oracle 9605 ebstest01 257u REG 8,33 40255488 0 5775361 /oradata/data_old/cntrl02.dbf (deleted)
oracle 9605 ebstest01 258u REG 8,33 40255488 0 9969665 /oradata/data_old/cntrl03.dbf (deleted)
oracle 9605 ebstest01 259uW REG 8,33 4294975488 0 2629640 /oradata/data_old/system01.dbf (deleted)
oracle 9605 ebstest01 260uW REG 8,33 4294975488 0 3678209 /oradata/data_old/system02.dbf (deleted)
oracle 9605 ebstest01 261uW REG 8,33 4294975488 0 3678210 /oradata/data_old/system03.dbf (deleted)
oracle 9605 ebstest01 262uW REG 8,33 4294975488 0 1597441 /oradata/data_old/system04.dbf (deleted)
oracle 9605 ebstest01 263uW REG 8,33 4294975488 0 1597448 /oradata/data_old/system05.dbf (deleted)
oracle 9605 ebstest01 264uW REG 8,33 4294975488 0 1597449 /oradata/data_old/system06.dbf (deleted)
oracle 9605 ebstest01 265uW REG 8,33 4294975488 0 1597450 /oradata/data_old/system07.dbf (deleted)
oracle 9605 ebstest01 266uW REG 8,33 4294975488 0 1597451 /oradata/data_old/system08.dbf (deleted)
oracle 9605 ebstest01 267uW REG 8,33 4632879104 0 4931624 /oradata/data_old/sysaux01.dbf (deleted)
oracle 9605 ebstest01 268uW REG 8,33 4554235904 0 4931599 /oradata/data_old/sysaux02.dbf (deleted)

And now kill the 3605 process.