Remove unused pacakges:
pacman -Rsn $(pacman -Qdtq)
List all unused packages:
pacman -Qdtq
Remove unused pacakges:
pacman -Rsn $(pacman -Qdtq)
List all unused packages:
pacman -Qdtq
This is how you can download an archive using curl:
curl -L -O https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz
-L
- Follow redirects-O
- Write output to a file named as the remote fileCopy files from a different server and preserv file owners, permissions.
rsync -avprog user@dns:/path/scripts destination
a
- Archive, don't know what it doesv
- Verbosep
- Preserve file permissionsr
- Reccursiveo
- Preserve file owners Needs rootg
- Preserve file group Needs roottail -f out | grep --line-buffered "text"
Or:
tail -f out | stdbuf -i0 -o0 -e0 grep "text"
On the server side:
tcpdump -n -i interface -n "src host client-host.com and dst port server-port"
You can get the client host using lsof
:
lsof -itcp -a -p server_pid
This will print all active tcp connections to the server app with the specific pid.
On the client side:
tcpdump -n -i interface -n "dst host server-host.com and dst port server-port"
interface
can be taken via ip addr
Let's say we have this diagram of servers:
A:9104 -> B -> C:9104
Connect from server A to server C via server B:
# We are here on server A and we run the following command:
ssh -N -f -L \*:9104:C:9104 user@B
# -N do not run any command on remote server
# -f run in background
# -L local forward
# \* - the 9014 port will be publically visible from outside of server A
Now to access C:9104
, you will be able to do it from A like this A:9104
.
Why would you want to do this? When you can't access directly the server C from server A, but you can access it from server B. And from server A you can access B. Voila!
Add the new architecture: sudo dpkg --add-architecture i386
Update the package database: sudo apt-get update
Install the libraries that you want: apt-get install libexpat1:i386
Print lines that matches a regex starting from a line that matches another regex until an until a line that matches a different regex:
cat file | awk '/startling_regex_excluded/{next} /printable_regex/{print} /until_regex/{exit}'
Having this file:
text
text2
startling_regex_excluded
printable_regex
printable_regex
printable_regex
until_regex
test
printable_regex
printable_regex
The output will be:
printable_regex
printable_regex
printable_regex
awk '/start line/{flag=1;next}flag' file.log
Debian host - ubuntu docker:
# Allow x11 forwarding
xhosts +
docker run --rm=true --name="container_name" -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix -it image_name /bin/bash
# This is the most important part from the command:
# -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix
We have three layers: A -> My desktop PC**B -> Host server(runs docker) C -> docker container that runs on BHow to connect to C and run a GUI app from A? Without having installed xserver on B** (no -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix
options given to the docker run command). I did it this way:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE in users profile
RUN echo export VISIBLE=now >> /etc/profile
EXPOSE 22
CMD [/usr/sbin/sshd, -D]
Build the image: docker build -t ubuntu_sshd .
Run the container: docker run -d -P --name test_sshd ubuntu_sshd
Get port of the docker container: docker port test_sshd 22
Now connect to it using ssh:
ssh root@ip -p port
# The password is ``screencast``.
root@f38c87f2a42d:/#
Enable X11Forwarding : Add X11Forwarding yes
to /etc/ssh/sshd_config
Disable X11UseLocalhost : Add X11UseLocalhost no to /etc/ssh/sshd_config
Reload ssh config: /etc/init.d/ssh reload
Exit from the ssh session
All those commands were made from the B machine(from 5 - 8 were run on the docker container)
Now go to your desktop machine A and connect via ssh on the docker machine(also enable x forwarding on your destktop PC), using the ip of B and the port you got from the command at step 4:
# Allow xserver forward(allow clients to connect to your x server)
$ xhost +
# Connect via ssh and forward the xserver `-X`
$ ssh -X root@B_host_ip -p docker_port
# The password is ``screencast``.
root@f38c87f2a42d:/# apt-get install x11-apps -y
root@f38c87f2a42d:/# xeyes
# Magic happens!!!
Debian:
# Debian with sshd
FROM debian
RUN apt-get update
RUN apt-get install -y openssh-server
RUN echo 'root:password' | chpasswd
RUN mkdir -p /var/run/sshd && sed -i s/UsePrivilegeSeparation.*//g /etc/ssh/sshd_config \
&& sed -i 's/PermitRootLogin without-password//' /etc/ssh/sshd_config \
&& touch /root/.Xauthority \
&& true
RUN sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN echo X11UseLocalhost no >> /etc/ssh/sshd_config
RUN echo PermitRootLogin yes >> /etc/ssh/sshd_config
RUN echo UsePrivilegeSeparation no >> /etc/ssh/sshd_config
EXPOSE 22
CMD [/usr/sbin/sshd, -D]
Resources: - Getting started with tmux - Youtube turorial 1 - Youtube turorial 2 Install tmux on Debian
sudo apt-get install tmux
You can also install tmuxinator, which is easier to use, you can create session easily. Tmux has a lot of keybindings, those keybindings are in this format CTRL + B [command]. The CTRL + B is called the prefix, it like letting tmux know that the next key pressed is a command for it. You press CTRL + B release and then press a letter(command). Each tmux session has a number of windows, and each window has a number of panes. Create a new tmux session:
tmux new -s name
Commands for windows: CTRL + B [command]- c - Creates a new window.
Commands for panes: CTRL + B [command]- % - Split vertically the current pane in two panes.
Move between panes : CTRL + B left-arrow/right-arrow/up-arrow/down-arrowResize current pane: CTRL + B left-arrow/right-arrow/up-arrow/down-arrow(but do not release CTRL) Set a predefined layout: CTRL + B Spacebar**Sessions:- CTRL + B** D - Detach from the session.
List all sessions:
tmux list-sessions
# or
tmux ls
Attach to a session:
tmux attach -t name_of_session
Running commands that do not have keybindings: CTRL + B :(two dots) [text-command]:- split-window - Splits the window horizontally
To scroll through output history: > Ctrl-b then [ then you can use your normal navigation keys to scroll around (eg. Up Arrow or PgDn). Press q to quit scroll mode. Alternatively you can press Ctrl-b PgUp to go directly into copy mode and scroll one page up (which is what it sounds like you will want most of the time)
More keybindings can be found here: http://tmuxcheatsheet.com/Tips:- To navigate through command history, use the mouse scroll
Change the config of tmux:- Create a config file in the home directory:
touch ~/.tmux.conf
# reload config file (change file location to your the tmux.conf file)
bind-key r source-file ~/.tmux.conf\; display-message Config reloaded.
Content of .tmux.conf:
# Create tmux work-session or attach to it if it already exist
######################### Script tmux_start.sh begin ###########################
#!/bin/bash
# new-window command or use alias neww
# send-keys 'cd ~/data/project' C-m \; \
# Sends the command from '' and C-m will execute it.
docker_container_running=$(docker ps | grep container_name_2 | wc -l)
SESSIONNAME="work_session"
tmux has-session -t $SESSIONNAME &> /dev/null
if [ $? -ne 0 ]
then
tmux new-session -s $SESSIONNAME\; \
send-keys 'cd ~/data/project' C-m \; \
rename-window "project" \; \
new-window -c ~/data/project1 -n 'project1' \; \
new-window -c ~/data/project2 -n "project2" \; \
new-window -c ~/data/project3 -n 'project3' \; \
new-window -c ~ -n 'home' \; \
new-window -n 'qserver_qtcreator' 'xhost +; if [ $(docker ps | grep container_name | wc -l) -eq 0 ]; then docker start -i container_name; else docker exec -it container_name /bin/bash; fi' \; \
split-window -h -c ~/data/project/source_1 \; \
split-window -v -c ~/data/project/source_1 'xhost +; if [ $(docker ps | grep container_name | wc -l) -eq 0 ]; then docker start container_name; fi; docker exec -it -e QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb container_name qtcreator' \; \
select-window -t "project_qtcreator"
else
tmux a -t $SESSIONNAME
fi
################################### End Script #################################
# Add alias command work-session in ~/.bashrc
alias work-session='bash ~/data/tmux_start.sh'
# Reload configuration
source ~/.bashrc