Change default SSH settings for remote host
Update .ssh/config
Host <host>
port <new_port>
user <new_user>
IdentityFile <new_file>
.ssh/config
Host <host>
port <new_port>
user <new_user>
IdentityFile <new_file>
To preset Tmux windows, following script can be used. It also issues ssh command to host which has same name as window name.
#!/bin/bash
WINDOWS="window_name1 window_name2 window_name3"
for each in $WINDOWS
do
if ! tmux has-session -t 0:$each; then
tmux new-window -n $each ssh $each
fi
done
tmux attach
Restore tmux session after reboot
Check If Window With a Specific Name Exists. If It Does Attach to it; Otherwise Create it and Run Command?
The unix command screen
and tmux
have similar goal, but tmux
is more complex than screen
.
In order to start using tmux
without worrying about forgetting keys, remember follows one after another.
Ctrl+b ?
Ctrl+b d
tmux a
Ctrl+b c
Ctrl+b w
, then arrow keysCtrl+b ,
<id>
Ctrl+b <id>
screen | tmux | |
---|---|---|
Startup | screen |
tmux |
Starting Named Session | screen -S session_name |
tmux new -s session_name |
List running session | screen -ls |
tmux ls |
Reattach | screen -r |
|
Reattach by id | screen -r <id> |
tmux attach-session -t <id> |
screen | tmux | |
---|---|---|
Help | Ctrl+a ? |
Ctrl+b ? |
Create a new shell (without window) | Ctrl+a c |
|
Switch to next shell | Ctrl+a space |
|
Switch to previous shell | Ctrl+a backspace |
|
Create a new window (with shell) | Ctrl+b c |
|
List all shells | Ctrl+a " |
|
Choose window from a list | Ctrl+b w |
|
Switch to N'th shell | Ctrl+a <n> |
|
Switch to N'th window | Ctrl+b <n> |
|
Rename the current window | Ctrl+a A |
Ctrl+b , |
Split current region horizontally into two regions | Ctrl+a S |
Ctrl+b % |
Split current region vertically into two regions | Ctrl+a | |
Ctrl+b " |
Switch the input focus to the next region | Ctrl+a tab |
Ctrl+b o |
Toggle between the current and previous windows | Ctrl+a Ctrl+a |
Ctrl+b ; |
Close all regions but the current one | Ctrl+a Q |
|
Close the current region | Ctrl+a X |
Ctrl+b x |
Detach from session | Ctrl+a d |
Ctrl+b d |
Sent Ctrl+a to region |
Ctrl+a a |
Customization can be done in /etc/screenrc
and ~/.screenrc
. Sample of contents is shown below.
# Turn off the welcome message
startup_message off
# Disable visual bell
vbell off
# Set scrollback buffer to 10000
defscrollback 10000
# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
Customization can be done in ~/.tmux.conf
. Sample of contents is shown below.
# Improve colors
set -g default-terminal 'screen-256color'
# Set scrollback buffer to 10000
set -g history-limit 10000
# Customize the status line
set -g status-fg green
set -g status-bg black
How To Use Linux Screen
Getting started with Tmux
How to split the terminal into more than one "view"?
~/.ssh/config
Add option to specific host for login user.
Host server_names
StrictHostKeyChecking no
/etc/ssh/ssh_config
This is to set for all servers and all users
StrictHostKeyChecking no
.xz
fileunxz < file.tar.xz > file.tar
When access remote servers, proxy server/jump host could be a good choice.
This is the proxy server, normally can be in the form of user@proxy_host
.
This is the target server, has the form of target_user@target_host
.
This is the most simplest method which uses remote ssh command to login to target server. If just wants to use one SSH server to access another SSH server, run following command
ssh -t <jump_host> ssh <target>
Here -t
is to create a pseudo-terminal, otherwise, the remote server could not display message because no tty can be used.
This is using SSH building proxy function.
ssh -o "ProxyJump <jump_host>" <target>
This is to run an external command to build communication. For example, use nc
command, and pass two parameters, %h
is the target host, %p
is the port.
ssh -o "ProxyCommand ssh <jump_host> nc %h %p" <target>
./ssh/cofig
Instead of using command, ProxyJump
and ProxyCommand
can be set in ssh client configuration file.
Host <connection_name>
HostName <target_host>
User <target_user>
ProxyCommand ssh <jump_host> nc %h %p
Host target
HostName 192.168.1.2
User user1
ProxyCommand ssh user2@proxy nc %h %p
Host * !proxy
HostName %h
User target_user
# ProxyCommand ssh proxy_user@proxy nc %h %p
/etc/ssh/ssh_config
This is the same as previous example, except it is a global setting.
tty
echo testing message | tee `tty` | more
Note: Some cases, tty
might not reply correctly when sub shell created in command line. In this case, better save tty in variable before execute into sub shell.
Use following command can clean up /var/log/journal
folder
journalctl --vacuum-size=500M
Today, migrate a few windows from smaller SSD larger one.
Use dd
command to duplicate from old device to new device
Use Partition Assistant - AOMEI
to move the last partition to the end
Use disk manager
extend partition.
dhclient -r
dhclient