New Post has been published on Tech & Cyber Security
New Post has been published on https://www.securityinet.com/useful-plesk-ssh-commands/
Useful Plesk SSH Commands
Useful Plesk SSH Commands
Below is a list of commands that can be run from a Linux shell session (i.e. over SSH) which will make administering a Plesk server much easier. Firstly because they can give you a lot of information at once which otherwise you would have to trawl through the web interface for, also more important features such as being able to find the usernames and passwords for different accounts (FTP, email, etc).All the commands below assume that you are logged onto the server that hosts Plesk via a SSH session as root or sat directly at the machine.
To show the Plesk admin account password: cat /etc/psa/.psa.shadow
To remove lockout from the admin user: mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âdelete from lockout where login=âadmin'â
To kill the admin session to allow another user to log in: mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âdelete from sessions where login=âadmin'â
To show all FTP users, their password and their domain: mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âSELECT home AS âHOMEDIRâ, login AS âUSERNAMEâ, password AS âPASSWORDâ FROM sys_users S, accounts A WHERE S.account_id = A.id ORDER BY home,account_id;â
To show all mailboxes, the usernames, passwords and associated domain: mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âSELECT name AS âDOMAINâ, mail_name AS âUSERNAMEâ, password AS âPASSWORDâ, postbox as âMAILBOX?â, redir_addr as REDIRECT FROM mail M, domains D, accounts A WHERE M.account_id = A.id AND M.dom_id = D.id ORDER BY name,mail_name;â
List all email addresses on the server: mysql âskip-column-names -B -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âSELECT CONCAT(mail_name, â@â, name) FROM mail M, domains D, accounts A WHERE postbox = âtrueâ AND M.account_id = A.id AND M.dom_id = D.id ORDER BY name,mail_name;â
To show mailboxes with a specific username, paste this and enter the name when prompted: echo -e ânnEnter mailbox usernameâ; read mbuser; echo â; mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âSELECT name AS âDOMAINâ, mail_name AS âUSERNAMEâ, password AS âPASSWORDâ FROM mail M, domains D, accounts A WHERE postbox = âtrueâ AND M.account_id = A.id AND M.dom_id = D.id AND mail_name = â$mbuserâ ORDER BY name,mail_name;â
To fix and optimise all MySQL databases and tables (i.e. to fix crashed or corrupted tables): mysqlcheck âauto-repair âoptimize -uadmin -p`cat /etc/psa/.psa.shadow` âall-databases
To show all MySQL processes and the process owner: mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âshow full processlistâ
To show the size of all websites, mailboxes, databases, backups and logs sorted by size: clear; if [ -d /var/www/vhosts ]; then echo -ne ânn=== WEBSITES ===nâ; cd /var/www/vhosts && du -ks âexclude=âchrootâ âexclude=âdefaultâ * | sort -nr | cut -f2 | xargs du -sh; echo â[`ls âignore=âchrootâ âignore=âdefaultâ | wc -l` Sites â Total `du -hs . | cut -f1`]â; fi; if [ -d /var/qmail/mailnames ]; then echo -ne ânn=== MAILBOXES ===nâ; cd /var/qmail/mailnames && TMB=$(du -ks */* 2>/dev/null | sort -nr | cut -f2); if [ -n â$TMBâ ]; then echo â$TMBâ | xargs du -sh; fi; echo â[`find . -mindepth 2 -maxdepth 2 -type d | wc -l` Mailboxes â Total `du -hs | cut -f1`]â; fi; if [ -d /var/lib/mysql ]; then echo -ne ânn=== MySQL DATABASES ===nâ; mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e âSELECT round(sum( data_length + index_length )/1024/1024,0) âSMâ, table_schema âDNâ FROM information_schema.TABLES GROUP BY table_schema ORDER BY SM DESC G;â | sed â/***/dâ | sed âs/SM: //â | sed â:a;N;$!ba;s/nDN:/Mt/gâ; fi; if [ -d /var/lib/psa/dumps/domains ]; then echo -ne ânn=== PLESK BACKUPS ===nâ; cd /var/lib/psa/dumps/domains && du -ks * | sort -nr | cut -f2 | xargs du -sh; echo â[Total `du -hs . | cut -f1`]â; fi; echo -ne ânn=== TEMP FILES ===nâ; du -hs /tmp /var/tmp; echo -ne ânn=== LOGS ===nâ; du -hs /var/log /usr/local/psa/var/log; echo -ne ânnâ;
To show all MySQL users and their allowed access host: mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âselect host, user from mysql.user;â
To show all MySQL databases, usernames and passwords on every domain: mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âSELECT d.name AS DOMAIN, db.name AS DB, du.login as USER, a.password as PASS FROM db_users du, data_bases db, domains d, accounts a WHERE du.db_id = db.id AND db.dom_id=d.id and du.account_id=a.id ORDER BY d.name, db.name;â
To show all information for a specific domain. Just replace example.org with the domain name in question: QDNAME=âexample.orgâ; echo -e ânnâ; mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e âSELECT login AS âFTP Usernameâ, password AS âPasswordâ FROM sys_users S, accounts A WHERE S.account_id = A.id AND home LIKE â%/$QDNAMEâ ORDER BY home,account_id; SELECT mail_name AS âMailbox Usernameâ, password AS âPasswordâ, postbox as âMailbox?â, redir_addr as âRedirect toâ FROM mail M, domains D, accounts A WHERE M.account_id = A.id AND M.dom_id = D.id AND name = â$QDNAMEâ ORDER BY name,mail_name; SELECT db.name AS âDatabase Nameâ, du.login as âDB Usernameâ, a.password as âPasswordâ FROM db_users du, data_bases db, domains d, accounts a WHERE du.db_id = db.id AND db.dom_id=d.id and du.account_id=a.id AND d.name = â$QDNAMEâ ORDER BY d.name, db.name;â; echo -e ânnâ;
To delete all emails currently in the QMail queue: service qmail stop && find /var/qmail/queue/mess,intd,local,remote,todo,info/ -type f -exec rm ; && service qmail start
 âŚ..













