Сообщения

Reset Root password in CentOS7

1. In boot menu press 'e' on the top kernel in the list 2. Move down, up to linux16 entry, at the end of the line remove "rhgb quiet" and add ''rd.break enforsing=0" 3. Press Ctrl+x 4. In command prompt type mount -o remount, rw /sysroot (read-write mode) 5. In command prompt type chroot /sysroot 6. In command prompt type passwd and type new password for root 7. In command prompt type exit 8. In command prompt type  mount -o remount, ro /sysroot   (read-only mode) 9. In command prompt type exit After boot process have finished , l ogin to system like a root with a new password. And restore the security context for the password file /etc/shadow. 10. In command prompt type restorecon /etc/shadow 11. In command prompt type setenforce 1

XRDP on Debian

Install XRDP and TigerVNC server. $ sudo apt install -y xrdp tigervnc-standalone-server Restart XRDP. $ sudo systemctl restart xrdp

Bash Shell: Check File Exists or Not

H ow do I test existence of a text file in bash running under Unix like operating systems? You need to use the test command to check file types and compare values. The same command can be used to see if a file exist of not. The syntax is as follows: test -e filename [ -e filename ]   test -f filename [ -f filename ] The following command will tell if a text file called /etc/hosts exists or not using  bash conditional execution  : [ -f / etc / hosts ] && echo "Found" || echo "Not found" Sample outputs: Found The same code can be converted to use with  if..else..fi  which allows to make choice based on the success or failure of a test command: #!/bin/bash file = "/etc/hosts" if [ -f " $file " ] then echo " $file found." else echo " $file not found." fi File test operators The following operators returns true if file exists: -b FILE ...

How to hide Postfix Headers

1. edit/create - # nano header_checks.pcre 2. ADD next Lines: /^Received:/         IGNORE /^User-Agent:/       IGNORE /^X-Mailer:/         IGNORE /^X-Originating-IP:/    IGNORE /^X-PHP-Originating-Script/ IGNORE 3. ADD next Lines: smtpd_sasl_authenticated_header = yes smtp_header_checks = pcre:/etc/postfix/header_checks.pcre  to main.cf         -o header_checks=pcre:/etc/postfix/header_checks.pcre to master.cf just after cleanup instruction 4. Restart postfix

NFS quick setup Debian

# aptitude install nfs-kernel-server nfs-common portmap Edit /etc/exports. Example for  NFSv3 /mnt/movie 192.168.0.0/24(rw,async,no_subtree_check) /mnt/user 192.168.0.41(rw,async,no_subtree_check) Example for NFSv4: /mnt 192.168.0.0/24(ro, fsid=0, async, no_subtree_check) /mnt/movie 192.168.0.0/24(rw, async, no_subtree_check) /mnt/user 192.168.0.41(rw, async, no_subtree_check) Permission nobody/nogroup for folder. After # /etc/init.d/nfs-kernel-server restart Client part: # aptitude install nfs-common portmap Mount directory: # mount -t nfs 192.168.0.2:/mnt/movie /home/movie # mount -t nfs 192.168.0.2:/mnt/user /home/user Mount with NFSv4: mount -t nfs4 192.168.0.2:/ /home/mnt Unmount # umount /home/movie Automatic mount Edit /etc/fstab: 192.168.0.2:/mnt/movie /home/movie nfs rw,async 192.168.0.2:/mnt/user /home/user nfs rw,async

Script for automatic backups XEN VM's on FTP

#!/bin/bash DATE=`date +%d_%m_%Y` XSNAME=`echo $HOSTNAME` HOST='YOUR FTP SERVER' PORT='FTP SERVER PORT' USER='FTP USER' PWD='FTP PASSWORD' FTP_SUCCESS_MSG="Connect" FTPLOG=/tmp/ftplogfile BACKUPPATH=/backups # check ftp echo ''> /tmp/ftplogfile telnet <<! > $FTPLOG open $HOST $PORT quit ! if fgrep "$FTP_SUCCESS_MSG" $FTPLOG ;then     echo "ftp OK"     mkdir -p $BACKUPPATH     rm -rf $BACKUPPATH/*     vmlist=$(xe vm-list tags:contains =daily is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2)     echo "$vmlist"     for vm in $vmlist         do             vmname=$(xe vm-list uuid=$vm | grep name-label | awk -F: '{print $2}' | tr -d " ")             echo $DATE - "Start making snaphot of - " $vmname >> /var/log/backups...

XEN script to get ssh access to guest VM

xenconsole.sh #!/bin/bash xl list; echo -n "Input VM name:"; read domname; echo -n "Input ssh username:"; read sshusername; domid=`xe vm-list | grep -B 1 $domname | grep uuid | awk '{print $5}'`; domip=`xe vm-param-list uuid=$domid | grep network | awk '{print $4}' | sed 's/;//g'`; ssh $sshusername@$domip;