help to edit: https://gist.github.com/PurpleBooth/109311bb0361f32d87a2
I used to search in net for commands syntax. it's better to collect them for others.
-
ctrl+alt+T to open a terminal
-
alt+F2 to execute a command without terminal
-
update url of wordpress
-
best way to replace all in editor
sed -i -e 's/http\:\/\/url\.com/http\:\/\/localhost\:port/g' hello.txt
- or update database
update wp_options set option_value = 'url:port' where option_name = 'siteurl';
update wp_options set option_value = 'url:port' where option_name = 'home';
UPDATE wp_links SET link_image = REPLACE(link_image,'old_url','');
UPDATE wp_links SET link_url = REPLACE(link_url,'old_url','');
UPDATE wp_posts SET post_content = REPLACE(post_content,'old_url','');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value,'old_url','');
ffmpeg -ss 00:00:00 -t 00:46:00 -i inputfile outputfile
- in error with :
ffmpeg -ss 00:00:00 -t 00:46:00 -i inputfile -max_muxing_queue_size 400 outputfile
find /<directory> -newermt "-24 hours" -ls
pop3 can delete on serve but IMAP not.
-
at the end of ssh session :
find / -mtime -1 |grep -v 'proc|module|cache|lib|kernel|/sys/|devices'
-
rm files that think log you
rm /var/log/wtmp /var/log/btmp /var/log/lastlog touch /var/log/wtmp /var/log/btmp /var/log/lastlog history -c
sudo vi /etc/default/grub
GRUB_CMDLINE_LINUX="text"
update-grub2
vi /etc/environment
export
> /dev/null 2>&1
??
docker exec -ti [name_of_ocsrv_container] ocpasswd -c /etc/ocserv/ocpasswd -g "Route,All" username
sudo openconnect [IP or URL] --user=username -p=password --authgroup=route --servercert sha256:[has given on first use from bash]
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
docker pull ubuntu
docker run -t -i ubuntu /bin/bash
docker ps
docker export ID | gzip > ubuntu.tar.gz
gzcat ubuntu.tar.gz | docker import - ubuntu-alice
docker save ubuntu | gzip > ubuntu-golden.tar.gz
gzcat ubuntu-golden.tar.gz | docker load
docker pull ubuntu
docker tag ubuntu another_repo
docker push another_repo
docker exec -i container_name mysql -uUser -pPassword --database=DBName < sqlfile
-
in /va/var/lib/docker/containers
grep -irn '"RestartPolicy":{"Name":"always"' | cut -d : -f 1
-
the result list is files with restartpolicy; change them to "RestartPolicy":{"Name":"no"
grep -irn '"RestartPolicy":{"Name":"always"' | cut -d : -f 1 | xargs -n 1 sed -i s/'"RestartPolicy":{"Name":"always"'/'"RestartPolicy":{"Name":"no"'/g
-
bash of docker container
docker exec -it container_name bash
-
add container.service to /etc/systemd/system/
[Unit] Description=Redis container After=docker.service
[Service] Restart=always ExecStart=/usr/bin/docker start -a redis_server ExecStop=/usr/bin/docker stop -t 2 redis_server
[Install] WantedBy=local.target
-
after changes:
docker commit container_name desired_name
docker exec -ti [name_of_ocsrv_container] bash -c 'command1;command2;....'
docker rm ocserv
service docker stop
service docker start
docker ps
RUN cd ~ \
&& curl -sS http://getcomposer.org/download/2.2.5/composer.phar -o composer.phar \
&& cp ~/composer.phar /usr/local/bin/composer \
&& chmod +x /usr/local/bin/composer
-
create and run new ocserv
-
https://github.com/TommyLau/docker-ocserv
sudo docker run --name [name_of_ocsrv_container] --privileged -p 443:443 -p 443:443/udp -d tommylau/ocserv
docker exec -it [ocserv_container_name] bin/bash
ps aux | grep ^test | cut -d \ -f 6
-
Stop and remove the existing container:
docker stop gitlab-runner && docker rm gitlab-runner
-
Start the container as you did originally:
docker run -d --name [container_name] --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:latest
docker run -d --name [container_name] --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /srv/gitlab-runner/config:/etc/gitlab-runner:Z gitlab/gitlab-runner:latest
<link rel="stylesheet" type="text/css" href="theme.css">
mongo
db.adminCommand('listDatabases')
use [dbname]
show collections
db.[collname].find()
db.[collname].update( { "[field]" : "[citria(first)]" }, { $set: { "[setfield]": "[updatedVal]" }, $currentDate: { "lastModified": true } //current date } )
db.users.update( {"username":"[username]"}, {$set :{"emails" : [ { "address" : "[email@domain.com]", "verified" : true } ] } })
export HISTCONTROL=ignoreboth:erasedups # in .bash_rc
export HISTFILESIZE= export HISTSIZE=
HISTCONTROL=ignoreboth
HISTTIMEFORMAT='%F %T '
PROMPT_COMMAND='history -a'
shopt -s histappend
shopt -s cmdhist
ps aux | grep [app_name] | cut -d \ -f 4,5,6 | xargs -n 1 kill -9
alias rm='rm -i'
- not sure to work history(){ if [ "$1" = "-c" ] then echo "are you sure to delete all history?(y/n):" if [ "$2" = "y" ] then history -c fi else history "$1" fi }
??
initd: /etc/init.d/[services] start/stop/status/restart/reload SysV: update-rc.d [service] remove/start/stop/status/restart/reload # or remove it from /etc/rc.* SystemD: systemctl disable/enable/start/stop/status/restart/reload [services] upstart: ??
su -c 'vi /etc/systemd/logind.conf'
- and set HandleLidSwitch to ignore: HandleLidSwitch=ignore
- and then restart systemd su -c 'systemctl restart systemd-logind.service'
ssh-keygen ssh-copy-id user@host
- https
- ??
- ssh
- ??
refrence: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-basic-iptables-firewall-on-centos-6
-
blocking null packets.
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
The attack patterns use these to try and see how we configured the VPS and find out weaknesses
-
reject syn-flood attack
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
attackers open a new connection, but do not state what they want (ie. SYN, ACK, whatever)
-
XMAS packets
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
-
Open all Local
iptables -A INPUT -i lo -j ACCEPT
-
Allow webserver traffic
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-
Allow email ports (SMTP,POP3,IMAP)
iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 465 -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 110 -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 995 -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 143 -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 993 -j ACCEPT
-
Allow SSH on desired port
iptables -A INPUT -p tcp -m tcp --dport [port] -j ACCEPT
-
Allow SSH on desired port for my IP
iptables -A INPUT -p tcp -s YOUR_IP_ADDRESS -m tcp --dport [port] -j ACCEPT
-
Allow us to use outgoing connections (ie. ping from VPS or run software updates);
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-
block everything else
iptables -P OUTPUT ACCEPT iptables -P INPUT DROP
ref: https://github.com/jrleszcz/linux-server-setup
-
edit sshd file /etc/ssh/sshd_config -change:
# Authentication: PermitRootLogin no
reload ssh
-
list virtual hosts
apachectl -M
-
check configuration
apachectl -t
- move current directory to remote git repository
- make a git repository in current directory
git init .
- add server side url to current git repository as remote
git remote add origin url
- add current files
git add .
- commit
git commit -m "first "
- push to server
git push -u origin master
- show configuration of git in current repository
git config --get remote.origin.url
git remote show origin
- create new branch and switch on it
git branch [new_branch_names]
git checkout [new_branch_names]
or you can use this shorthand
git checkout -b [new_branch_names]
- merge two branches (hotfix into master)
(https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging)
git checkout master
git merge iss53
in conflict use mergetool
git mergetool
- list all git brances
(http://gitready.com/intermediate/2009/02/13/list-remote-branches.html)
git branch
git branch -a
git branch -r #
- create new migration
for update:
php artisan make:migration [some_name_as_comment] --table=[table_name]
const script = document.createElement('script');
script.src =
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js';
script.onload = () => {
console.log('Script loaded successfuly');
};
script.onerror = () => {
console.log('Error occurred while loading script');
};
document.body.appendChild(script);