mysql < mysqldump.sql
When restoring a dump of all tables from a different machine (e.g. using a dump from the production server on the VM), this will override the debian-sys-maint
user (as well as other users and passwords).
Detele the sections Table structure for table `user`
and Dumping data for table `user`
from the mysqldump file (or see http://serverfault.com/questions/9948/what-is-the-debian-sys-maint-mysql-user-and-more for how to fix). But it's probably easier/better to just use dumps of single tables instead.
Check which distribution is installed (on a vserver):
cat /etc/*-release
lsb_release -a
Find [XXX]
tags:
grep -r "\[XXX\]" /etc/ /usr/local/bin/
Find config files that diff from their .deb:
debsums -se
Find non-config files that diff from their .deb:
debsums -s
Find which package a config file is from:
dpkg -S <config-file>
Replace a missing config file from it's package:
apt-get install --reinstall -o Dpkg::Options::="--force-confmiss" <package>
Check apache2 config:
apache2ctl configtest
Show loaded apache2 modules:
apache2ctl -M
Check nginx config:
nginx -t
Tomcat logs:
less +F /var/log/tomcat7/catalina.out
less +F /var/log/tomcat7/localhost<TAB>
Apache2 logs:
less +F /var/log/apache2/access.log
less +F /var/log/apache2/error.log
less +F /var/log/apache2/mod_jk.log
Update and run rkhunter:
rkhunter --update && rkhunter --check --skip-keypress
less +F /var/log/rkhunter.log
Change a mysql user password:
echo "SET PASSWORD FOR 'user'@'localhost' = PASSWORD('password');" | mysql
Delete a line from bash history (e.g. a password):
history -d <line-number> && history -w
Edit the mysql history
nano ~/.mysql_history
Clean package cache (run before making a backup to make it smaller):
aptitude clean
Show changelog for a package:
apt-get changelog <package-name>
Set package on hold (dpkg, apt-get, and apticron use a different method than aptitude; better do both):
apt-mark hold <package-name>
aptitude hold <package-name>
Tomcat server info:
java -cp /usr/share/tomcat7/lib/catalina.jar org.apache.catalina.util.ServerInfo
Find high priority packages that are not installed, or automatically installed:
aptitude search '(~prequired|~pimportant|~pstandard)(!~i|~M)'
Find manually installed, low priority packages:
aptitude search '(~poptional|~pextra)~i!~M'
Find manually installed, low priority, libary packages (except apache modules):
aptitude search '^lib!libapache(~poptional|~pextra)~i!~M'
Write list of low priority packages from remote host to file:
ssh "$host" 'aptitude search "(~poptional|~pextra)~i!~M" -F "%p"' > "$host-packages"
List packages with user-tags:
aptitude search '?user-tag()' -F '%p %T'
List third-party packages (not from the Debian repo):
aptitude search '~S ~i !~ODebian !~o'
Show last logged in users
last -w
Also show shutdown entries
last -w -x
Change when apticron runs (edit the time it ran last time; it runs every 24 hours; the minute is specified in /etc/cron.d/apticron
)
touch -d "today 06:00" /var/lib/apticron/{cron,last}_run
Playback a collectl log with all columns
collectl --all -p /var/log/collectl/*.raw.gz
Playback a collectl log with CPU, memory, disk and network columns
collectl -s cmdn -p /var/log/collectl/*.raw.gz
Recursive chmod for files/directories:
find <parentdir> -type d -exec chmod 755 {} \;
find <parentdir> -type f -exec chmod 644 {} \;
Find files older than a given days:
find . -mtime +7
Find files older than a specific date:
find . ! -newermt 20170101
sudo aptitude update
sudo aptitude upgrade
sudo aptitude purge '~c'
sudo aptitude autoclean
sudo aptitude clean
sudo apt-file update
sudo updatedb
sudo aptitude reinstall -o Dpkg::Options::=--force-confmiss $packagename
or from .deb file
dpkg -i --force-confmiss ${package}.deb
aptitude search '~i!~M!'
aptitude search '~i!~M(~poptional|~pextra)'
aptitude search '~S~i~Brecommends'
aptitude search '~i!~M!~rforeign'
aptitude search '~i!~M!~ODebian'
aptitude search ~mmarillat@deb-multimedia.org
aptitude search '~i!~M(~poptional|~pextra)(~dtransitional|~ddummy)'
Show automatically installed packages that are not a dependency or recommendation of any package (only a suggestion)
aptitude search '~i~M!~Rdepends:~i!~Rrecommends:~i'
apt-show-versions | grep unstable
deborphan
deborphan --all-packages --no-show-section --priority optional | sort
sudo update-alternatives --get-selections
sudo update-alternatives --all
sudo update-java-alternatives -l
sudo update-java-alternatives -s java-6-sun
history -c
sudo find -L /usr -type l -ls
with color
sudo find -L /usr -type l -exec ls -lF --color=yes '{}' +
sudo cruft --ignore "/dev /proc /sys /tmp /var /opt /usr/local /usr/lib/pymodules /boot/grub /boot/efi /home" -r "$HOME/cruft_report-$(date "+%Y-%m-%d_%H-%M-%S")"
Non-configuration files
sudo debsums -cg
Configuration files
sudo debsums -ceg
All files
sudo debsums -cag
sudo dpkg --verify
Quick over-all health of all disks
for dev in $(sudo smartctl --scan | cut -d" " -f1); do echo "${dev}:"; sudo smartctl -H $dev | \grep "result"; done
Detailed information of a device, e.g. /dev/sda
sudo smartctl -i /dev/sda
clamscan -ri --log=clamscan.log /
Monitor scanning process
watch -n 1 "ps u -C clamscan"
Download and install from http://free.avg.com/us-en/download.prd-alf
sudo avgctl --start
sudo avgupdate
sudo avgscan -awmP --report avgscan.log /
sudo grep -r -A 1 --exclude-dir=.git PATTERN /etc
Search for pattern in hidden files and directories in ~
sudo grep -r -A 1 --include=.* PATTERN ~
sudo find /etc -regextype posix-egrep -regex '.*\.((dpkg)|(ucf))-((bak)|(dist)|(old)|(remove))'
Delete
sudo find /etc -regextype posix-egrep -regex '.*\.((dpkg)|(ucf))-((bak)|(dist)|(old)|(remove))' -delete
for files:
find $path -type f -exec chmod $expression {} \;
for directories:
find $path -type d -exec chmod $expression {} \;
e.g.:
find . -type f -exec chmod u=rw,go=r {} \;
find . -type d -exec chmod u=rwx,go=rx {} \;
verbose:
find . -type f -print -exec chmod u=rw,go=r {} \;
find . -type d -print -exec chmod u=rwx,go=rx {} \;
install and run 'netselect-apt' copy the created sources.list file or parts from it to /etc/apt/sources.list
to show all installed packages
aptitude search ~i
to show only manually installed packages
aptitude search '!~M~i'
to further exclude packages of of high priority (standard, important, required) and essential packages, use
aptitude search '!~pstandard!~pimportant!~prequired!~E!~M~i'
- ~i installed packages
- ~M automatically installed packages
- ~E essential packages
- ~p packages with given priority
- ! not
show package versions
apt-show-versions
e.g. to show all packages not from lenny use
apt-show-versions | grep -v lenny
or to show packages from lenny-backports
apt-show-versions | grep backports
or to show manually upgardeable packages
apt-show-versions | grep manually
run
aptitude install `apt-show-versions -u -b | grep $pattern`
to upgrade only packages that match $pattern
aptitude search '~i!~M!~o!~ODebian'
show available versions and apt pinning priorities for package $packagename
apt-cache policy $packagename
aptitude install $packagename=$version
e.g.
aptitude install virtualbox-ose=3.1.4-dfsg-1~bpo50+1
dpkg-reconfigure keyboard-configuration
setupcon # from package console-setup
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales
netstat -tuna | grep :80 | grep SYN_RECV
Fix for the following warnings when running apt: upgrade debconf
to >= 1.5.57
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^(.*?)(\\)?\${ <-- HERE ([^{}]+)}(.*)$/ at /usr/share/perl5/Debconf/Question.pm line 72.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^}]+)}/ at /usr/share/perl5/Debconf/Config.pm line 30.