Hiển thị các bài đăng có nhãn Linux. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Linux. Hiển thị tất cả bài đăng

Thứ Sáu, 6 tháng 10, 2017

Installing Nginx on DirectAdmin

By default, DirectAdmin is deployed with the Apache web server. Converting this (including current websites) to Nginx can be done using its CustomBuild tool. After completing this guide, you will have a DirectAdmin server featuring an Nginx reverse proxy as its web server.

Step 1: Altering the CustomBuild configuration

cd /usr/local/directadmin/custombuild
./build set php1_mode php-fpm
./build set php2_mode php-fpm
./build set php1_release 7.0
./build set php2_release 5.6
./build php n
./build set webserver nginx_apache
./build update
./build all d
./build rewrite_confs

Nginx will now be installed.
Read More

Thứ Tư, 27 tháng 4, 2016

Reset a lost password on an Ubuntu VM / CentOS VM

CentOS 6

    Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
    You will see a GRUB boot prompt telling you to press any key - you have only a few seconds to press a key to stop the automated booting process. (If you miss this prompt you will need to restart the VM again)
    At the GRUB prompt, type "a" to append to the boot command.
    Add the text "single" and press enter.
    System will boot and you will see the root prompt. Type "passwd" to change the root-password and then reboot again.
Debian, Ubuntu, CentOS 7

    Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
    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. (If you do not see the GRUB prompt, you may need to press any key to bring it up before the machine boots)
    Find the kernel line (starts with "linux /boot/") and add init="/bin/bash" at the end of the line (On CentOS 7, the line may start with linux16).
    Press CTRL-X or F10 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 reboot again.

FreeBSD

The boot menu has an option to boot into single-user mode. Press the key for single user mode (2). At the root prompt, type "passwd" to change the root password and then reboot again.
CoreOS

CoreOS by default uses SSH key authentication. On Vultr, a root user and password are created. If an SSH key is selected when creating the VPS, this SSH key can be used to login as user "core".

It is possible to reset the standard root login by executing "sudo passwd" as user "core". Login as "core" using the SSH key first.

If you lost your SSH key, then you can login as the "core" user by editing the grub loader. Follow these steps:

    Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.
    You will see a GRUB boot prompt - press "e" to edit the first boot option. (If you do not see the GRUB prompt, you may need to press any key to bring it up before the machine boots)
    At the end of the line that begins with "linux$" add " coreos.autologin=tty1" (no quotes).
    Press CTRL-X or F10 to boot. You will be logged in as "core" when the system boots.
    Remember to reboot your server after you have reset your login.
Read More

Thứ Ba, 17 tháng 11, 2015

How to install configure printers on Linux

Install required packages
apt-get install cups cups-client "foomatic-db".
Add user to lpadmin group
adduser root lpadmin
Output
 Adding user `root' to group `lpadmin' ...
 Adding user root to group lpadmin
 Done.
Restart cups and samba service
service cups restart 
service samba restart
 Find USB printer
netstat -ant | grep 631 
lsusb
Configuring Printer
     Open browser and type:
    http://127.0.0.1:631/
    In semicolon: CUPS for Administrators
    Click on Adding Printers and Classes
    Click on Add printer
    Type your username(system account) and password(system password)
    Choose your printer
    Follow instructions to complete rest of the installation……
    In System Settings: Go and check
        Printers
    You’ll see your installed printer
Is the printer on Win7 shared? 
try adding it directly using one of the following URI examples:

smb://WORKGROUP_NAME/MACHINE_NAME/PrinterName
smb://MACHINE_NAME/PrinterName
smb://192.168.0.100/PrinterName
List samba shares
smbclient -L < Windows host name > -U < Windows Administrator account >

Read More

Thứ Bảy, 31 tháng 1, 2015

Disable The Mail Alert By Crontab Command

ow do I to disable the mail alert send by crontab? When my job is executed and the jobs cannot run normally it will sent an email to root. Why do I receive e-mails to my root account from cron? How can I prevent this?

By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append following string:

Cron Job Prevent the sending of errors and output To prevent the sending of errors and output, add any one of the following at the end of the line for each cron job to redirect output to /dev/null.
>/dev/null 2>&1.
OR
&> /dev/null
Cron Job Example
Edit/Open your cron jobs, enter:
$ crontab -e
Append string >/dev/null 2>&1 to stop mail alert:
0 1 5 10 * /path/to/script.sh >/dev/null 2>&1
OR
0 1 5 10 * /path/to/script.sh &> /dev/null
Save and close the file. Restart the crond:
# /etc/init.d/crond restart
MAILTO variable
you can set MAILTO="" variable at the start of your crontab file. This will also disable email. Edit/Open your cron jobs
$ crontab -e
At the top of the file, enter:
MAILTO=""
Save and close the file.
Read More

Delete all root mail / inbox from a shell prompt

The easilst way is to empty root / users email message file i.e. /var/spool/mail/root or /var/spool/mail/username. Simply type the following command at shell:
> /var/spool/mail/root 
OR
cat /dev/null > /var/spool/mail/root 
OR
echo "" > /var/spool/mail/root
Read More

Chủ Nhật, 18 tháng 1, 2015

How to export PUTTY Sessions List

How to export PUTTY Sessions List 

You can export it simply by:

regedit /e "%userprofile%\desktop\putty-sessions.reg" HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions
 
Or:
regedit /e "%userprofile%\desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham
Read More

Thứ Sáu, 5 tháng 9, 2014

Set File Attributes In Linux Using Chattr Command

 Set File Attributes In Linux Using Chattr Command

Chattr is a command used to set / unset file attributes in Linux.
Using chattr it is possible to make a file immutable. That is, even a root user will be prohibited from deleting the file.
To prevent anyone - even a root user - from deleting a file, you set the immutable bit of the file using the chattr command as follows -

# chattr +i filename

The immutable bit option +i can only be set by the root user. So either you should have root priviledges or you need to use sudo to execute the command.
Once the +i bit is set, even root user won't be able to delete or tamper with the file.

To unset the immutable flag -

# chattr -i filename

chattr can be used to set/unset many more file attributes.

For example, if you want to allow everybody to just append data to a file and not change already entered data, you can set the append bit as follows:

# chattr +a filename


Now the filename can only be opened in append mode for writing data. You can unset the append attribute as follows:

# chattr -a filename


To know more about chattr command, check its man page. 
Read More

Thứ Sáu, 16 tháng 5, 2014

Disable exim email on single cPanel Account

Disable exim email on single cPanel Account 

A week ago one of our clients account been compromised and the attacker used the server to blast emails.
as a system administrator my task was to prevent any outgoing email from the account before I start to investigate the attack and remove any kind of scripts from the hosting account.

Studying cPanel files made me to come around following solution.
To disable email for one account we can change the permission of /etc directory for that particular user, using our root power simply use following commands:
chmod 0 /home/username/etc
chattr +ia /home/username/etc
You need to replace username with your user username. Once this is done the user will not be able to send anymore emails from local server. To undo this you should run the chattr once more:
chattr -ia /home/username/etc
chmod 750 /home/username/etc
Read More

Thứ Năm, 27 tháng 3, 2014

Calculating Maximum Connections for MySQL Server

Calculating Maximum Connections for MySQL Server


Backup your my.cnf file

The my.cnf file is the MySQL configuration file that needs to be modified to optimize the performance of MySQL database servers. Make sure you always backup a copy of this very important configuration before changing it.

Determine the advisable value for max_connections

How high should we set max_connections? Well, it depends on how much memory (RAM) do you have on the server.
You might want to use the formula to come up with the value we are looking for.
max_connections = (Available RAM - Global buffers) / Thread buffers

But before that, we need to know the values of the variables on our right side - available RAM, global buffers, and thread buffers.

Determine the Available RAM

To determine the Available RAM, issue the following command.
free -tb
Here's the result of the command in my case:
The number in red is the available memory measured in bytes.

Determine the Global and Thread Buffers

In a mysql console, issue the following statement:
SHOW VARIABLES LIKE '%buffer%';
The following are considered global buffers:
key_buffer_size
innodb_buffer_pool
innodb_log_buffer
innodb_additional_mem_pool
net_buffer_size
The following are considered thread specific buffers:
sort_buffer_size
myisam_sort_buffer_size
read_buffer_size
join_buffer_size
read_rnd_buffer_size

Read More

Thứ Tư, 26 tháng 3, 2014

Delete IPTables Rules By Line Number

Delete IPTables Rules By Line Number

First off list all IPTable's rules by chain number:
iptables -vnL --line-numbers
Then delete the line you want:
iptables -D INPUT 22
This will delete chain line number 22
Read More

Chủ Nhật, 16 tháng 3, 2014

[Step by step]Create a MySQL Database, Username, Password, and Privileges from the command line

Create a MySQL Database, Username, Password, and Privileges from the command line

Step 1: Login to MySQL ( you will need an account )

user@server:~$ mysql -u mysql_user -p
Enter password:

Step 2: Create the Database

mysql > create database db_name;

Step 3: Verify that it’s there

mysql > show databases;

Step 4: Create the User

mysql > create user db_user;

Step 5: Grant privileges while assigning the password

mysql > grant all on db_name.* to 'db_user'@'localhost' identified by 'db_password';
*Note: The localhost field usually doesn’t have to be edited, but you can set it to the specific address.

The above example grants all privileges, obviously. But you will likely want to limit privileges under many circumstances. These parameters include select, insert, and delete.
Choose all that apply and separate by comma, thusly:
mysql > grant select, insert, delete on db_name.* to 'db_user'@'localhost' identified by 'db_password';
Read More

Thứ Năm, 6 tháng 3, 2014

How to change Mysql data directory location?

How to change Mysql data directory location?

Mysql is most famous open source RDBMS (Relational database management system) software used by millions of websites.
Most of website with very large Mysql database experience storage problem because /var partition is to small which holds Mysql data files and folder by default.
If you are experiencing such a problem then you have to move your Mysql data directory to other linux partition (eg: /home).
To change your directory without affecting Mysql configuration. Follow these steps.

Note: before changing Mysql data directory please backup all your database

mysqldump --all-databases | gzip > /home/alldatabases.sql.gz

  • First stop Mysql service
/etc/init.d/mysqld stop
  • create a folder 'mysql' in /home partition
  • copy whole Mysql data directory to 'mysql' in preserve mode
cp –pr /var/lib/mysql/ /home/mysql

-p means preserve the specified attributes (default: mode, ownership, timestamps)

-r means copy each directory sub-directory and files

  • then create a symbolic link from new data directory to old data directory
ln -s /home/mysql/ /var/lib/mysql/

  • Now start Mysql service
/etc/init.d/mysqld start
  • If its working properly then delete each file and folder from old data directory
cd /var/lib/mysql rm –rf  *
Read More

Chủ Nhật, 19 tháng 5, 2013

How to install Linux Malware Detect (LMD)

How to install Linux Malware Detect (LMD)


Maldet also known as Linux Malware Detect virus scanner for Linux.

Download the tar file using the below link:

    wget http://www.rfxn.com/downloads/maldetect-current.tar.gz

Extract the file using the below command

    tar -xzf maldetect-current.tar.gz

go to the maldet folder

    cd maldetect-*

Now, run the below command to install maldet.

    sh ./install.sh or sudo sh ./install.sh

It will give below output

    Linux Malware Detect v1.3.4
    (C) 1999-2010, R-fx Networks <proj@r-fx.org>
    (C) 2010, Ryan MacDonald <ryan@r-fx.org>
    inotifywait (C) 2007, Rohan McGovern <rohan@mcgovern.id.au>
    This program may be freely redistributed under the terms of the GNU GPL

    installation completed to /usr/local/maldetect
    config file: /usr/local/maldetect/conf.maldet
    exec file: /usr/local/maldetect/maldet
    exec link: /usr/local/sbin/maldet
    cron.daily: /etc/cron.daily/maldet

    maldet(32517): {sigup} performing signature update check…
    maldet(32517): {sigup} local signature set is version 2010051510029
    maldet(32517): {sigup} latest signature set already installed

    

To update the maldet use the below commands.

    maldet –update-ver

    maldet –update[/i]

To scan the files.

    maldet -a /home/username/

It will scan all the files and provide you the output.



To scan all user uder public_html paths under /home*/ this can be done with:

    root@server[~]# maldet –scan-all /home?/?/public_html

To scan the same path but the content that has been created/modified in the last 5 days:

    root@server[~]# maldet –scan-recent /home?/?/public_html 5

To scan but forget to turn on the quarantine option, you could quarantine all malware results from a previous scan with:

    root@server[~]# maldet –quarantine SCANID

If you wanted to attempt a clean on all malware results from a previous scan that did not have the feature enabled, you would do with.

    root@server[~]# maldet –clean SCANID

If you had a file that was quarantined from a false positive or that you simply want to restore (i.e: you manually cleaned it), you can use the following:

    root@server[~]# maldet –restore config.php.2384
    root@server[~]# maldet –restore /usr/local/maldetect/quarantine/config.php.2384

 
Read More