Sunday, May 14, 2017

sftp Couldn't remove directory: Failure


using SFTP to connect to other servers , you ma get this error when trying to delete a folder "sftp Couldn't remove directory: Failure" , this because the folder is not empty , so try the command ls -a to show the hidden files , then remove them and try again .

Sometimes when you try to remove a full 100% folder (on Hetzner) , you cannot do that unless you use put command to replace the folder you want to remove by a null size folder with same name.

Note: that put command on ssh uses -r argument for the folders with identical names source and destination. which means it expects a folder with a same name from the command sftp -r source

Monday, December 26, 2016

mysql short commands

login to mysql as root with password
mysql -u root -p
list users
SELECT User FROM mysql.user;

nohup to Import osm planet into postgres

To keep the process running after closing the ssh connection, specially when using that in a very long process, Using this command the program will run in background and you can close your terminal, also it will not log anything to disk
must be from osm account
  
nohup osm2pgsql --slim -d gis -C 16000 --hstore -S openstreetmap-carto-2.45.1/openstreetmap-carto.style planet-latest.osm.pbf > /dev/null 2>&1&

If you prefer to save nodes to file :
  
nohup osm2pgsql --slim -d gis -C 16000 --hstore --flat-nodes ~/flat_nodes/flatnodes -S openstreetmap-carto-2.45.1/openstreetmap-carto.style planet-latest.osm.pbf > /dev/null 2>&1&

Thursday, December 22, 2016

Prepare Ubuntu FireWall

Prepare Ubuntu FireWall


if you want a good reference that will take you in step by step way check this link


 
    sudo apt-get update

    sudo apt-get install iptables-persistent



Keep established connections allowed

    iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT



Accept all packets destined to port 22 or 80


    iptables -A INPUT -p tcp --dport 22 -j ACCEPT

    iptables -A INPUT -p tcp --dport 80 -j ACCEPT




Accept all loopback communications and put the first rule

    sudo iptables -I INPUT 1 -i lo -j ACCEPT

 

  Let Mysql Server accept connections from private network

    iptables -A INPUT -p tcp --dport 3306 -s 192.168.0.0/24 -j ACCEPT    



Drop any other Packets not matching our rules.

    iptables -A INPUT -j DROP

OR for better resoaning
    iptables -A INPUT -j REJECT

check this Drop vs Reject
Note : the last rule must be the last rule to be added.

If you ever update your firewall and want to preserve the changes, you must save your iptables rules for them to be persistent.

Save your firewall rules with this command:

    sudo service netfilter-persistent save

sudo iptables -I INPUT 1 -i lo -j ACCEPT

insert this rule on the first row to accept ll packets coming from interface lo
to list line numbers in iptables use this command
sudo iptables -L --line-numbers

to insert the new rul on specific line do the following
sudo iptables -I INPUT 4 new_rule_here

To delete rule by line Number
sudo iptables -D INPUT 3

To export firewall rules use :
sudo iptables-save > iptables-export

To accept on a range of ports :
sudo iptables -A INPUT -p tcp --match multiport --dports 1024:3000 -j ACCEPT

To import firewall rules use :
sudo iptables-restore < iptables-export 

To Block all connections on port 111, prefer to the end of the list
 iptables -I INPUT -p udp  --dport 111 -j REJECT 

To allow all communication on the private network on interface ens19
iptables -A INPUT -i ens19 -s 192.168.100.0/24 -j ACCEPT

So, the minimum required rules in nutshell

 sudo iptables -I INPUT 1 -i lo -j ACCEPT
 sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
 sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
 sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
 sudo iptables -A INPUT -i ens19 -s 192.168.100.0/24 -j ACCEPT
 sudo  iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
 sudo iptables -A INPUT -j REJECT

Tuesday, December 13, 2016

mount exist hard disk in debian

check if the drive is exist or not :
fdisk -l
if the disk is there
check if the partition is mounted or not
df -h
if the disk exist and not partitioned yet , then you have to do so using :

fdisk /dev/sdb1

mkdir /newstorage
chmod 755 /newstorage

mkfs.ext4 /dev/sdb1

mount /dev/sdb1  /newstorage 

Add this line to /etc/fstab
/dev/sdb1  /newstorage ext4 defaults 0 10
 
mount /newstorage 
 OR
mount -t ext4 /dev/sda1 /newstorage


Friday, October 7, 2016

Using Winscp as Sudo User to edit files remotely - Ubuntu 16.04

On the new version of Ubuntu Server 16.04 , you cannot have a root user account but you can create a user account with root privileges only when strat your command with sudo, And that made it very difficult for people who are using Winscp as their daily tool to interact with a headless server to edit files and save them , you will get an error  message  saying "Permission Denied".

After Searching google for a suitable solution for this problem, I didn't find anything related directly to Ubuntu 16.04.
The direct dirty trick is to give the ubuntu user the full  root privileges by editing sudoers file "/etc/sudoers", then add the following line at the end of the file :

username ALL=NOPASSWD: ALL

Change username by the account name you are using to login to the system through Winscp.
On the client side choose advanced and sftp and insert the location of sftp server
sudo /usr/lib/openssh/sftp-server in case of ubuntu 16.04


Reference credits goes to chilcano

Wednesday, May 11, 2016

Cannot load modules/mod_ssl.so into server: The operating system cannot run The Apache service named. .

in Windows, If you have Event 3299 error in the event viewer::
The Apache service named  reported the following error:
>>> httpd.exe: Syntax error on line 167 
Cannot load modules/mod_ssl.so into server: The operating system cannot run The Apache service named.

Then check the VC compatibility , I had this error when I tried to run Apache 2.4.20  VC14 ( C++ Redistributable Visual Studio), with php 5.6 which compiled using VC11, which is not compatible, So to solve this issue there are two methods:
The first is upgrade PHP by downloading the  PHP version compiled with VC14, Or to downgrade Apache server and download the VC11 version.
Apache Versions can be downloaded from http://www.apachelounge.com.
Php versions can be downloaded from http://windows.php.net/download/