kill -9 $(lsof | grep deleted | cut -d " " -f4)
Category Archives: Linux
Ip-Table block-range-of-ip-addresses
To block 116.10.191.* addresses:
$ sudo iptables -A INPUT -s 116.10.191.0/24 -j DROP
To block 116.10.*.* addresses:
$ sudo iptables -A INPUT -s 116.10.0.0/16 -j DROP
To block 116.*.*.* addresses:
$ sudo iptables -A INPUT -s 116.0.0.0/8 -j DROP
Saving and restoring rules
$sudo aptitude install iptables-persistent After the installation the initial setup will ask to save the current rules for IPv4 and IPv6, just select Yes and press enter for both. If you make further changes to your iptables rules, remember to save them again using the same command as above. The iptables-persistent looks for the files rules.v4 and rules.v6 under /etc/iptables.
Download complete website excepting some extensions
use linux command to download all website excepting .js, .css, .gif, .png, .mp3, .exe
wget –mirror –random-wait –remote-encoding=utf-8 –reject ‘*.js,*.css,*.gif,*.png,*.mp3,*.exe’ [http://www.website.com]
Split contents of a directory into multiple sub directories
Just run this and hit enter in tme command line
i=0;
for f in *;
do
d=dir_$(printf %03d $((i/100+1)));
mkdir -p $d;
mv "$f" $d;
let i++;
done
ENABLE ROOT LOGIN OVER SSH
-
As root, edit the sshd_config file in
/etc/ssh/sshd_config
:nano /etc/ssh/sshd_config
-
Add a line in the Authentication section of the file that says
PermitRootLogin yes
. This line may already exist and be commented out with a “#”. In this case, remove the “#”.# Authentication: #LoginGraceTime 2m PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10
-
Save the updated
/etc/ssh/sshd_config
file. -
Restart the SSH server:
service sshd restart
Reset a MySQL root password
Stop the MySQL service
(Ubuntu and Debian) Run the following command:
sudo /etc/init.d/mysql stop
(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following command:
sudo /etc/init.d/mysqld stop
Start MySQL without a password
Run the following command. The ampersand (&) at the end of the command is required.
sudo mysqld_safe --skip-grant-tables &
Connect to MySQL
Run the following command:
mysql -uroot
Set a new MySQL root password
Run the following command:
use mysql;
update user set password=PASSWORD("mynewpassword") where User='root';
flush privileges;
quit
Stop and start the MySQL service
(Ubuntu and Debian) Run the following commands:
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following commands:
sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start
Rsync command
Copy a File from a Remote Server to a Local Server with SSH
rsync -avzhe ssh root@[server-ip]:/root/source/ /dest/
Copy a File from a Local Server to a Remote Server with SSH
rsync -avzhe ssh backup.tar root@[server-ip]:/backups/
allow root access in phpmyadmin
skip Configuring phpmyadmin in installation steps
login to mysql
mysql -u root -p mysql
write this mysql command
update user set plugin='' where user='root';
flush privileges;
exit
systemctl restart apache2
Extending a Linux File System IN amazon EC2
1- expand the volume from amazon ec2 Volumes dashboard
2- Expand the modified partition using growpart
sudo growpart
/dev/xvdf 1
A look at the lsblk output confirms that the partition /dev/xvdf1
now fills the available space on the volume /dev/xvdf
3-
sudo resize2fs
/dev/xvdf1
Change all files permissions to 644 and folders permissions to 755
find * -type d -print0 | xargs -0 chmod 0755 # for directories
find . -type f -print0 | xargs -0 chmod 0644 # for files