setup sftp only user for web

Step 1: Create a dedicated sFTP group and a dedicated sFTP user

groupadd sftpusers
useradd -G sftpusers -s /sbin/nologin user1
passwd user1
Here, the group sftpusers is a dedicated sFTP group, the user user1 is a dedicated sFTP user which is forbidden to log in using SSH.

Step 2: Modify the configuration of the sshd service

Open the configuration file of the sshd service:
vi /etc/ssh/sshd_config
Find the line:
Subsystem sftp /usr/libexec/openssh/sftp-server
Replace it with:
Subsystem sftp internal-sftp
Append the following lines to the end of the file. The group name sftpusers should be the same as the one you specified earlier.

Subsystem sftp internal-sftp
    Match Group sftpuser
    ChrootDirectory %h
    X11Forwarding no
    AllowTcpForwarding no
    ForceCommand internal-sftp
    AllowAgentForwarding no

Save and quit:
:wq
Restart the sshd service to put your changes into effect.
systemctl restart sshd.service

Step 3: Create a dedicated directory for the sFTP-only user

You need to specify a directory for the sFTP-only user and make sure that this user can only play around in this directory:
chown -R root /home/user1
chmod -R 755 /home/user1
mkdir /home/user1/files
chown user1. /home/user1/files
Now, the user user1 can only upload and/or download files in the directory /home/user1/files, he or she can never touch other users' files.

Step 4: Create more sFTP-only users

If you need more sFTP-only users, you can create them in the same fashion:
useradd -G sftpusers -s /sbin/nologin user2
passwd user2
chown -R root /home/user2
chmod -R 755 /home/user2
mkdir /home/user2/files
chown user2. /home/user2/files
That's it. Each user account created in this fashion will be denied if you use it to log in the system. These user accounts can be used only in sFTP programs.

send mail attachment with mutt from terminal

 echo "body part" | mutt -s "subject header file" -a radius.tar.gz -- ndgen@qmail.com  
 echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com  
 echo "This is the message body" | mutt -s "subject of message" -e 'my_hdr From:sender@company.com' -- rcv1@exg.org,jack@abc.com 


#!/bin/bash
bounced='/var/log/bouncedmail/bouncedlog.txt'
filteredlist='/var/log/bouncedmail/bounced-maillist.txt'
rm -f $bounced
rm -f $filteredlist
curmonth=`date | cut -d' ' -f 2`
for var in `ls /var/log/maillog*`
do
    if [ $# -eq 3 ]
      then
          echo "Script error please supply log filename and month For Example. scanmaillog.sh maillog-20170130 "; exit 1;
      else
          grep "status=bounced" $var | grep -v classic.com.np | grep $curmonth | awk  '{ print $1" " $2 " "$7; }' | sed -e 's/to=<//g' -e 's/>,//g' >> /var/log/bouncedmail/bouncedlog.txt
    fi
cat /var/log/bouncedmail/bouncedlog.txt | cut -d' ' -f 3 | sort | uniq  >> /var/log/bouncedmail/bounced-maillist.txt
done
cat  $filteredlist | grep -v "axiata" | sort | uniq > /var/log/bouncedmail/filtered.txt
cat /var/log/bouncedmail/filtered.txt | mail  -s "Total: `wc -l $bounced | cut -d' ' -f1` emails bounced for month of `date | cut -d' ' -f2` 2017" -S smtp="mail.classic.com.np:25" urgen@classic.com.np,wilson@classic.com.np,jayesh@classic.com.np,manu@classic.com.np;

git for managing web public html directory


On GitServer [ ip:192.168.0.123 ]

useradd gituser1 -m -s /bin/bash

mkdir -p /project/ecommerceweb
chown -R gituser1:gituser1 /project


cd /project/ecommerceweb
git init --bare

Note:-To have separate worktree

vim /project/ecommerceweb/hooks/post-receive

#!/bin/bash
GIT_WORK_TREE=/webdir/web git checkout -f

#<save/exit>

chmod +x /project/ecommerceweb/hooks/post-receive



On git client [ ip:192.168.0.123 ]

#copy your ssh public key to git server for user "gituser1" for passwordless ssh and public/private key based authentication

ssh-copyid gituser1@192.168.0.239

git clone ssh://gituser1@192.168.0.239/project/ecommerceweb
cd ecommerceweb
vim index.php
... < add your code /save/exit> ..

git add . # add files to index
git commit -m "initial commit added index page" #Record changes to the repository
git push origin master #push changes to git server
git status

git remote show origin #shows your remote gitserver url OR use

git config --get remote.origin.url



View changed files in your working repository

## git status

Git log

show all git commits

## git log

Git diff

made changes to tracked files

## git diff

Git branch

list all branches

## git branch


ispconfig3 freshclam command error

ERROR: /var/log/clamav/freshclam.log is locked by another process
ERROR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log).


had to ---> sudo /etc/init.d/clamav-freshclam stop

then sudo freshclam -v

and it worked for me.

then restart the daemon with

sudo /etc/init.d/clamav-freshclam start

after it was restarted i was able to run the freshclam -v command with no more porblems. thinking it might have been locked up..??

aws RDS for external mysql master

http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Importing.External.Repl.html

mysql error #1005 - Can't create table (errno: 150) importing database from another server

http://stackoverflow.com/questions/9018584/error-code-1005-cant-create-table-errno-150/30102503#30102503
Reference link to stackoverflow

This could also happen when exporting your database from one server to another and the tables are listed in alphabetical order by default.
So, your first table could have a foreign key of another table that is yet to be created. In such cases, disable foreign_key_checks and create the database.
Just add the following to your script:

vim export.sql

use  databasename100;
SET FOREIGN_KEY_CHECKS=0;
..
..
...sql'sss ....

and it shall work.



reset user password using GRUB and set grub password in the end Ubuntu 14.04 LTS

on boot menu

select  "e" to edit the menu item
find line starting with "linux..." and in the end append  init=/bin/bash
and press
ctrl+x

mount -o remount,rw /
passwd <username>
reboot -f

To set grub password

login as root

# grub2-mkpasswd-pbkdf2 
OR
grub-mkpasswd-pbkdf2

Password: ****
Reenter password: ****
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.9CA4611006FE96BC77A

Paste the encrypted long string into the file /etc/grub.d/40_custom

eg. copy the content starting from "grub.pbkdf2.sha512.10000.9CA461100..."

vim /etc/grub.d/40_custom

set superusers="root"
password_pbkdf2 root grub.pbkdf2.sha512.10000.9CA4611006FE96BC77A...

grub2-mkconfig -o /boot/grub2/grub.cfg
or 
grub-mkconfig -o /boot/grub2/grub.cfg

if on the local terminal use help of "tee"

grub-mkpasswd-pbkdf2 | tee myhelper.txt

your password content and other text are copied in myhelper.txt, edit this myhelper.txt file and cat its content to /etc/grub.d/40_custom

cat myhelper.txt >> /etc/grub.d/40_custom
grub-mkconfig -o /boot/grub2/grub.cfg

apache xss protection headers

Setting up Apache to emit NoSniff, X-Frame and X-XSS-Protection headers

Security Headers is a service which checks that your web server is not revealing too much information. It does this by checking the HTTP headers returned with every request. The service checks to see if the server information is being leaked or if it’s reporting what scripting language is being used in the X-Powered-By header.
The service also checks and reports on a list of useful security headers like NoSniff, which prevents browsers from MIME-sniffing a response away from the declared content-type. It also checks for headers which prevent clickjacking and cross site scripting by detecting if X-Frame-Options and X-XSS-Protection are defined.

Add the headers to the Apache config file

I decided it would useful to implement these headers on the web servers I support. In particular I wanted to prevent other sites from framing my content within an iframe. By setting the X-Frame-Options to deny I am explicitly disallowing framing of any type. After a little research, these are the headers that my servers now emit:
<IfModule mod_headers.c>
    Header unset ETag
    Header set X-Frame-Options: deny
    Header set X-XSS-Protection: "1; mode=block"
    Header set X-Content-Type-Options: nosniff
    Header set X-WebKit-CSP: "default-src 'self'"
    Header set X-Permitted-Cross-Domain-Policies: "master-only"
</IfModule>
If your using the Joomla CMS, then using deny on the X-XSS-Protection will prevent the media manager from working properly. In this case you will need to relax the setting to use the same origin policy:

Header set X-Frame-Options: sameorigin

ssh error

root@server1:~# service ssh restart
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
[....] Restarting OpenBSD Secure Shell server: sshdCould not load host key: /etc/ssh/ssh_host_ecdsa_key

The root cause of this problem is that sshd daemon somehow is not able to load SSH host keys.
When OpenSSH server is first installed on Linux system, SSH host keys should automatically be generated for subsequent use. If, however, key generation was not finished successfully, that can cause SSH login problems like this.
Let's check if SSH host keys are found where they should be.
$ ls -al /etc/ssh/ssh*key 
make sure size is not zero,
good example:-
 root@server1:~# ls -al /etc/ssh/ssh*key
-rw------- 1 root root  668 Nov 30 18:12 /etc/ssh/ssh_host_dsa_key
-rw------- 1 root root  227 Dec  5 15:03 /etc/ssh/ssh_host_ecdsa_key
-rw------- 1 root root 1675 Nov 30 18:12 /etc/ssh/ssh_host_key
-rw------- 1 root root 1671 Nov 30 18:12 /etc/ssh/ssh_host_rsa_key

[SOLUTION - debian / ubuntu ]
root@server1:~# dpkg-reconfigure openssh-server
Creating SSH2 ECDSA key; this may take some time ...
[ ok ] Restarting OpenBSD Secure Shell server: sshd.

[SOLUTION - redhat/centos]
On CentOS, RHEL or Fedora, all you have to do is to restart sshd after removing existing (problematic) keys.
$ sudo rm -r /etc/ssh/ssh*key

$ sudo systemctl restart sshd

An alternative way to regenerate SSH host keys is to manually generate them using ssh-keygen command.
$ sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
$ sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key 
Once new SSH host keys are generated, make sure that they are found in /etc/ssh directory. There is no need to restart sshd at this point.
$ ls -al /etc/ssh/ssh*key
Now try to SSH again to the SSH server to see if the problem is gone.

ispconfig 3 phpmyadmin 404 not found error


ln -s /usr/share/phpmyadmin /var/www/
service nginx restart

mysupermarket.com/phpmyadmin

enter user/password and login...this will redirecto below url

http://mysupermarket.com/index.php?token=81d1f26028dc0f0f625803c2d1ccd402

it will still give

ERROR 404 - Not Found!
The following error occurred:
The requested URL was not found on this server.
Please check the URL or contact the webmaster.

insert phpmyadmin between domain.com and index.php.... like below
http://mysupermarket.com/phpmyadmin/index.php?token=81d1f26028dc0f0f03c2d1ccd402#PMAURL:server=1&target=main.php&token=81d1f26028dc0f0f625803c2d1ccd402










still need to fix....