# nano /etc/rc.d/rc.local
Add the following line
mount /dev/sdb1 /backup
Where /dev/sdb1 if the partition and backup is the desired mount point
- cheat_sheet.org
- (C) William Hackmore, 2010
- The contents of this file are released under the GNU General Public License. Feel free to reuse the contents of this work, as long as the resultant works give proper attribution and are made publicly available under the GNU General Public License.
- Last updated 8/14/2012
- Best viewed in emacs org-mode.
- Command Reference:
- Basics:
- Getting help:
- Basics:
- View the manual for target command
man [command]
- Get help with a target command (probably the same as above, but not always):
[command] -h
- In case you forget the name of a command, print possible commands relating to [guess]:
apropos [guess]
- View index of help pages:
info
-
-
- Command Line Utilities:
- Basic File and Directory Operations:
- Command Line Utilities:
-
- Print current working directory:
pwd
- Show files in current directory:
ls
- Show maximum information about all files, including hidden:
ls -a
- Recurse into subdirectories and list those as well:
ls -r
- Move/rename a file or directory (be careful that you don’t move the source over a destination with the same name):
mv [source] [destination]
- Delete target forever (be very careful), use -r recursive flag for directories:
rm [target]
- Copy file or directory:
cp [source] [destination]
- Mount filesytem:
mount /dev/[device name] /media/[device name]
- Unmount:
umount /media/[device name]
- Forensically clone filesystems and do other low-level operations on files. Very dangerous:
dd
- Work with filesystems and partitions. (Easier, still quite dangerous):
fdisk
-
-
-
- System Administration:
-
-
- Execute command as an administrator (dangerous, but necessary for system administration tasks):
sudo [command]
- Become system administrator:
sudo -s
- Quit system administration:
exit
- Check distro repositories for software updates:
sudo apt-get update
- Download and install updates (update first):
sudo apt-get upgrade
- Search for package in the repositories:
apt-cache search [keyword]
- Get more detail on one specific package:
apt-cache show [package name]
- Download and install a package:
sudo apt-get install [package name]
- View the output of a command in a more convenient format:
[command] | less
-
-
-
- Working With Files:
-
-
- Print a file in terminal:
cat [file]
- Find files matching [filename]:
locate [filename]
- Search through [filename] for matches to [phrase]:
grep [phrase] [filename]
- Search through output of a command for [phrase]:
[command] | grep [phrase]
-
-
-
- Working With Processes:
-
-
- List all running processes:
ps -e
- Standard system monitor showing a more extensive view of all processes and system resources:
top
- Like top, but with a better, cleaner interface:
htop
- Stop a process from using all system resources and lagging computer:
nice [process name]
- Kill misbehaving process (use sparingly, last resort, try ‘nice’ command first):
pkill [process name]
-
-
-
- Compression and Encryption:
-
-
- Make a simple compressed backup of a file or directory:
tar -cvzf [backup output.tgz] [target file or directory]
- Open a compressed .tgz or .tar.gz file:
tar -xvf [target.tgz]
- Encrypt a file:
gpg -o [outputfilename.gpg] -c [target file]
- Decrypt a file:
gpg -o [outputfilename] -d [target.gpg]
- Zip and encrypt a directory simultaneously:
gpg-zip -o encrypted-filename.tgz.gpg -c -s file-to-be-encrypted
-
-
- The Bash shell:
- File Name expansions:
- The Bash shell:
-
- Current user’s home directory:
~/
- Current directory:
./
- Parent directory:
../
- Or even (Two parent directories down):
../../
- All files in target directory. (Be very careful.):
/*
-
-
-
- Output Redirects:
-
-
- Redirect output of one command into the input of another with a pipe:
[command 1] | [command 2]
- Or even:
[command 1] | [command 2] | [command 3]
- Redirect output to a file:
[command] > file
- Or:
[file] > [file]
- Or even, to redirect in a different direction:
[file] < [file]
- Append output rather than writing over the target file:
[file/command] >> [file]
- Works like |, but it writes output to both target and terminal:
tee [target]
-
-
-
- Controlling Execution:
-
-
- Wait until [command 1] is finished to execute [command 2]
[command 1] ; [command 2]
- Or even:
[command 1] ; [command 2] ; [command 3]
-
-
-
- Wildcards:
-
-
- Zero or more characters:
*
- Matches “phrase” and any number of trailing characters:
phrase*
- Matches any incidences of “phrase” with any trailing or leading chars:
*phrase*
- Matches any one char:
?
- Matches any of the characters listed inside brackets:
[chars]
- Matches a range of chars between a-z:
[a-z]
-
- Advanced:
- Command Line Utilities, Continued:
- Networking:
- Command Line Utilities, Continued:
- Advanced:
- Configure network interfaces:
ifconfig
- Configure wireless network interfaces:
iwconfig
- Connect to a remote server.
ssh [username]@[ipaddress]
- Forward x from target to current machine (Get a remote desktop. Very obscure and very useful):
ssh -x [username]@[ipaddress]
- Copy files over the network from one machine to another:
scp [source filename]:[username]@[ipaddress] [target filename]:[target username]@[target ipaddress]
- Copy only changes between files or directories (super efficient way to sync directories, works either locally or with remote servers using username@ipaddress:optionalport, just like ssh):
rsync [source] [target]
- Check to see if target is online and responding
ping [ip address]
- View network route to target:
traceroute6 [ip address]
- Network Monitor
netstat
- Manage standard linux firewall (advanced users only)
iptables
- Scan this machine to check for open ports:
nmap 127.0.0.1
-
-
-
-
- netcat:
-
-
-
- Listen for input from network on [recieving port], dump it to a file (possibly insecure):
netcat -l [recieving port] > file_copied
- Pipe the output of a command to a target ip and port over the network:
[command] | netcat -w [number of seconds before timeout] [target ip] [target port]
- Use tar to compress and output a file as a stream, pipe it to a target ip and port over the network:
sudo tar -czf - [filename] | netcat -w [number of seconds before timeout] [target ip] [target port]
-
-
-
- Users and Groups:
-
-
- Change owner of a file or directory:
chown
- Change privileges over file or directory:
chmod
- Create a new user:
adduser
- Change user privileges (be very careful with this one):
usermod
- Delete user”
deluser
- Print groups:
groups
- Create a new group:
groupadd
- Change group privileges:
groupmod
- Delete group:
delgroup
- Temporarily become a different user:
su [username]
- Print usernames of logged in users:
users
- Write one line to another user from your terminal:
talk
- Interactive talk program to talk to other users from terminal:
ytalk
-
-
-
- Working With Files, Continued:
-
-
- View what processes are using what files:
lsof
- View the differences between two files:
diff [file 1] [file 2]
- Output the top -n lines of [file]:
head -n [number of lines] [file]
- Like head, but it outputs the last -n lines:
tail
- Checksum a file:
md5sum [file]
- Checksum every file in a directory:
md5deep [directory]
- Checksum a file (safer algorithm with no hash collisions):
sha1sum
- Same operation as md5deep, but using sha1:
sha1deep
- Call [command] every -n seconds, and display output:
watch -n [number of seconds] [command]
- Execute [command], print how long it took:
time [command]
- View files in home from largest to smallest:
du -a ~/ | sort -n -r | less
- remove spaces from filenames in current directory
rename -n 's/[\s]/<i>/g' *</i>
- change capitals to lowercase in filenames in current directory
rename 'y/A-Z/a-z/' *
-
-
-
-
- Environment and Hardware:
-
-
-
- Print full date and time:
date
- Print the hostname of this machine:
echo $HOSTNAME
- Print information about current linux distro:
lsb_release -a
- Print linux kernel version:
uname -a
- Print information about kernel modules:
lsmod
- Configure kernel modules (never do this):
modprobe
- View Installed packages:
dpkg --get-selections
- Print environment variables:
printenv
- List hardware connected via PCI ports:
lspci
- List hardware connected via USB ports:
lsusb
- Print hardware info stored in BIOS:
sudo dmidecode
- Dump captured data off of wireless card:
dumpcap
- Dump info about keyboard drivers:
dumpkeys
-
-
-
-
- System Administration (Continued):
-
-
-
- Add a Personal Package Archive from Ubuntu Launchpad:
add-apt-repository
- Install a .deb file from command line:
sudo dpkg -i package.deb
-
-
-
- Python:
-
-
- update pip (Python package manager):
pip install -U pip
- search pip repos
pip
- create a virtual python environment
virtualenv [dirname] --no-site-packages
- connect to a virtual python environment
source [dirname]/bin/activate
- disconnect from a python environment:
deactivate
- install package into virtual python environment from outsie:
pip install [packagename]==[version_number] -E [dirname]
- export python virtual environment into a shareable format:
pip freeze -E [dirname] > requirements.txt
- import python virtual environment from a requirements.txt file:
pip install -E [dirname] -r requirements.txt
-
-
-
- git (all commands must be performed in the same directory as .git folder):
-
-
- Start a new git project:
git init
- Clone a git (target can be specified either locally or remotely, via any number of protocols):
git clone [target]
- Commit changes to a git:
git commit -m "[message]"
- Get info on current repository:
git status
- Show change log for current repository:
git log
- Update git directory from another repository:
git pull [target]
- Push branch to other repository:
git push [target]
- Create a new branch:
git branch [branchname]
- Switch to target branch:
git checkout [branchname]
- Delete a branch:
git branch -d [branchname]
- Merge two branches:
git merge [branchname] [branchname]
-
-
- Virtualization:
-
- clone a virtual machine (this works, it’s been tested):
vboxmanage clonehd [virtual machine name].vdi --format VDI ~/[target virtual machine name].vdi
- mount a shared virtual folder:
- you need to make sure you have the right kernel modules. You can do this with modprobe, but this package works instead in a ubuntu-specific way.
sudo apt-get install virtualbox-ose-guest-utils
sudo mount -t vboxsf [name of Shared folder specified in Virtualbox] [path of mountpoint]
-
-
- mysql:
-
- Get help:
help
- Show databases:
show databases;
- Choose a database to use:
use [database name here];
- Show database schema:
show tables;
- Delete database:
DROP DATABASE [databasename];
- New database:
CREATE DATABASE [databasename];
- Create a new user:
CREATE USER [username@localhost] IDENTIFIED BY '[password]' ;
- Show users:
select * from mysql.user;
- Delete a user:
delete from mysql.user WHERE User='[user_name]';
- Give user access to all tables (make them root). the “%” means that they can sign in remotely, from any machine, not just localhost.:
grant all privileges on *.* to someusr@"%" identified by '[password]';
- give certain privileges to a user on a certain database:
grant select,insert,update,delete,create,drop on [somedb].* to [someusr]@["%"] identified by '[password]';
- Tell mysql to use new user priv policies:
flush privileges;
- change user password:
use mysql;
update user set password='[password]'(‘[newpassword]’) where User='[user_name]’ ;
- mysql command line args:
- export text file with commands to rebuild all mysql tables:
mysqldump [databasename] > [dumpfilename.txt]
- restore from a dump:
mysql -u [username] -p < [dumpfilename.txt]
- dump entire database:
mysqldump -u [username] -p --opt [databasename] > [dumpfile.sql]
- restore from entire database dump:
mysql -u [username] -p --database=[databasename] < [dumpfile.sql]
http://kb.odin.com/en/881
The issue is that cpanel from the https://domain.com:2083 looks like its missing css or files…
Symptom:
You try to access your cPanel behind CloudFlare and are finding that on the first page load that no images (or stylesheets or javascript) load – and, when trying to navigate to any link, you are immediately logged out. The experience is as if cPanel were broken in some way.
Cause:
cPanel has an option called “Cookie IP Validation”. This setting checks that the IP address that the visitor originally came from matches their IP address on subsequent requests. With CloudFlare, the IP address for requests to your server can variably come from any IP address in the list at https://www.cloudflare.com/ips
Resolution:
To resolve this issue, in your WHM, navigate to “Tweak Settings” -> “Security” -> “Cookie IP Validation”. On this screen, set the value for “Cookie IP Validation” to “disabled”. After this, loading your cPanel WHM interface through CloudFlare should work as expected.
Other resources:
https://forums.cpanel.net/threads/cpanel-looks-stupid-when-i-log-in.266321/
https://support.cloudflare.com/hc/en-us/articles/200169276-How-do-I-use-cPanel-with-CloudFlare-
Linux:
# mysql -uadmin -p`cat /etc/psa/.psa.shadow` DATABASE_NAME
Windows:
This will retrieve admin password
cd %plesk_bin% plesksrvclient -get
Login to mysql
cd %plesk_dir%\mysql\bin mysql -uadmin -pPassword -P8306
Install APCu. APC is not supported after php 5.4
Edit php.ini
extension="apcu.so" ; APC Configuration apc.enabled = 1 apc.shm_segments = 1 apc.shm_size = 128M apc.max_file_size = 2M apc.ttl = 7200 apc.user_ttl = 7200 apc.num_files_hint = 1024 apc.enable_cli = 1
Restart apache
Is it mysql or maria?
# service mysqld status Redirecting to /bin/systemctl status mysqld.service mysqld.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)
]# systemctl status mariadb.service mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled) Active: active (running) since Mon 2015-10-05 21:03:57 EST; 3min 30s ago Process: 26953 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 26922 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 26952 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─26952 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─27120 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock Oct 05 21:03:55 domain.com mysqld_safe[26952]: 151005 21:03:55 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Oct 05 21:03:55 domain.com mysqld_safe[26952]: 151005 21:03:55 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql Oct 05 21:03:57 domain.com systemd[1]: Started MariaDB database server.
Find the existing password
# cat /etc/psa/.psa.shadow $AES-128-CBC$MnglmyKq3wJbZVgmb4YKTQ==$p/zX+xpnhJ20kIrrZiFsq7VLE3kI+86JwVdPYJtWdEE=[root@69-64-92-195 ~]#
Stop the database
]# systemctl stop mariadb.service
Edit my.cnf and add skip-grant-tables
[mysqld] local-infile=0 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd skip-grant-tables [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
Restart mysql
# systemctl restart mariadb.service
Reset the mysql password no
# mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa mysql> UPDATE mysql.user SET Password=PASSWORD('# mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa mysql> UPDATE mysql.user SET Password=PASSWORD('$AES-128-CBC......') WHERE User='admin';') WHERE User='admin';
Edit my.cnf and remove skip-grant-tables
[mysqld] local-infile=0 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd # skip-grant-tables [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid
Install RPMForge on CentOS 6
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm # rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
Import RPMForge Repository Key in CentOS 6
# wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt # rpm --import RPM-GPG-KEY.dag.txt
Install Mtop in CentOS 6
Once you’ve installed and enabled RPMForge repository, let’s install MTOP using following YUM command.
# yum install mtop
To start Mtop program, you need to connect to your MySQL Server, using following command.
# mysql -u root -p
Then you need to create separate user called mysqltop and grant privileges to him under your MySQL server. To do, this just run the following commands in mysql shell.
mysql> grant super, reload, process on *.* to mysqltop; Query OK, 0 rows affected (0.00 sec) mysql> grant super, reload, process on *.* to mysqltop@localhost; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit; Bye
Let’s start the Mtop program.
# mtop
Sample Output:
load average: 0.03, 0.06, 0.08 mysqld 5.5.44-cll-lve up 4 day(s), 19:08 hrs 12 threads: 1 running, 0 cached. Queries/slow: 5/0 Cache Hit: 100.00% Opened tables: 0 RRN: 332 TLW: 1 SFJ: 0 SMP: 0 QPS: 0 ID USER HOST DB TIME COMMAND STATE INFO 39965 mysqltop localhost Query show full processlist
Monitor Remote MySQL Server using Mtop
# mtop –host=remotehost –dbuser=username –password=password –seconds=1