Copy a directory from local machine to remote machine using rsync
rsync -avz -e 'ssh -p 22002' /root/backup/monitoring_201909280430 [email protected]:/root/backup/
rsync -avz -e 'ssh -p 22002' /root/backup/monitoring_201909280430 [email protected]:/root/backup/
Start a new session
tmux tmux new tmux new-session
Start a new session with the name mysession
tmux new -s mysession
kill/delete session mysession
tmux kill-session -t mysession
kill/delete all sessions but the current
tmux kill-session -a
kill/delete all sessions but mysession
tmux kill-session -a -t mysession
Show all sessions
tmux ls tmux list-sessions
Attach to a session with the name mysession
tmux a -t mysession tmux at -t mysession tmux attach -t mysession tmux attach-session -t mysession
Rename session
Ctrl + b $
Detach from session
Ctrl + b d
Create window
Ctrl + b c
Rename current window
Ctrl + b ,
Close current window
Ctrl + b &
Previous window
Ctrl + b p
Next window
Ctrl + b n
Switch/select window by number
Ctrl + b 0 ... 9
Scroll
Ctrl-b [ # Press q to quit scroll mode
Ctrl-b PgUp
References
https://tmuxcheatsheet.com/
https://gist.github.com/MohamedAlaa/2961058
#!/usr/bin/expect spawn ssh [email protected] expect "assword:" send "mypassword\r" interact
References
https://stackoverflow.com/questions/16928004/how-to-enter-ssh-password-using-bash
To keep an SSH connection alive, you can modify your SSH configuration to send periodic keepalive messages. Here are a few methods to achieve this:
/etc/ssh/ssh_config
or ~/.ssh/config
):
nano ~/.ssh/config
Host * ServerAliveInterval 60 ServerAliveCountMax 3
ServerAliveInterval
specifies the interval in seconds between keepalive messages.ServerAliveCountMax
specifies the number of keepalive messages that can be sent without receiving a response from the server before the connection is terminated./etc/ssh/sshd_config
):
sudo nano /etc/ssh/sshd_config
ClientAliveInterval 60 ClientAliveCountMax 3
ClientAliveInterval
specifies the interval in seconds that the server will wait before sending a null packet to the client to keep the connection alive.ClientAliveCountMax
specifies the number of client alive messages which may be sent without receiving any messages back from the client.sudo systemctl restart sshd
chmod 600 deployment_key.txt
ssh -i deployment_key.txt [email protected]
References
https://support.rackspace.com/how-to/logging-in-with-an-ssh-private-key-on-linuxmac/
Create the RSA Key Pair
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Copy the Public Key to Ubuntu Server
cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
or Copying Public Key Manually
To display the content of your id_rsa.pub key, type this into your local computer:
cat ~/.ssh/id_rsa.pub
You will see the key’s content, which should look something like this:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqql6MzstZYh1TmWWv11q5O3pISj2ZFl9HgH1JLknLLx44+tXfJ7mIrKNxOOwxIxvcBF8PXSYvobFYEZjGIVCEAjrUzLiIxbyCoxVyle7Q+bqgZ8SeeM8wzytsY+dVGcBxF6N4JS+zVk5eMcV385gG3Y6ON3EG112n6d+SMXY0OEBIcO6x+PnUSGHrSgpBgX7Ks1r7xqFa7heJLLt2wWwkARptX7udSq05paBhcpB0pHtA1Rfz3K2B+ZVIpSDfki9UVKzT8JUmwW6NNzSgxUfQHGwnW7kj4jp4AT0VZk3ADw497M2G/12N0PPB5CnhHf7ovgy6nL1ikrygTKRFmNZISvAcywB9GVqNAVE+ZHDSCuURNsAInVzgYo9xgJDW8wUw2o8U77+xiFxgI5QSZX3Iq7YLMgeksaO4rBJEa54k8m5wEiEE1nUhLuJ0X/vh2xPff6SQ1BL/zkOhvJCACK6Vb15mDOeCSq54Cr7kvS46itMosi/uS66+PujOO+xt/2FWYepz6ZlN70bRly57Q06J+ZJoc9FfBCbCyYH7U/ASsmY095ywPsBo1XQ9PqhnN1/YOorJ068foQDNVpm146mUpILVxmq41Cj55YKHEazXGsdBIbXWhcrRf4G2fJLRcGUr9q8/lERo9oxRm5JFX6TCmj6kmiFqv+Ow9gI0x8GvaQ== demo@test
make sure the ~/.ssh directory exists.This command will create the directory if necessary, or do nothing if it already exists:
mkdir -p ~/.ssh
Now, you can create or modify the authorized_keys file within this directory. You can add the contents of your id_rsa.pub file to the end of the authorized_keys file, creating it if necessary, using this command:
echo public_key_string >> ~/.ssh/authorized_keys
Finally, we’ll ensure that the ~/.ssh directory and authorized_keys file have the appropriate permissions set:
chmod -R go= ~/.ssh
or Copy using ssh-copy-id
ssh-copy-id [email protected] ssh-copy-id [email protected] -p 22000 ssh-copy-id -i id_rsa.pub -p 22000 "[email protected]"
use -i identity_file
for other identities
Authenticate to Ubuntu Server Using SSH Keys
ssh username@remote_host
Disable Password Authentication on your Server
sudo nano /etc/ssh/sshd_config
PasswordAuthentication no
sudo systemctl restart ssh
Convert private key to putty
puttygen keyname -o keyname.ppk
ssh “permissions are too open” error
Keys need to be only readable by you:
chmod 400 ~/.ssh/id_rsa
If Keys need to be read-writable by you:
chmod 600 ~/.ssh/id_rsa
References
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-1604
https://haydenjames.io/how-to-convert-openssh-keys-to-putty-ppk-on-linux-with-puttygen/
https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
https://stackoverflow.com/questions/9270734/ssh-permissions-are-too-open-error
Connecting to a database behind a firewall
ssh -L 9000:localhost:5432 [email protected]
Remote port forwarding
ssh -R 9000:localhost:3000 [email protected]
sudo nano /etc/ssh/sshd_config GatewayPorts yes sudo service ssh restart
apt-get install libgcrypt11-dev zlib1g-dev
Edit the sshd config:
vi /etc/ssh/sshd_config
Find the line:
#Compression delayed
Change it to
Compression yes
Reboot the server. (Restarting sshd is not enough)
References :
https://www.namhuy.net/2430/install-enable-zlib-linux-server.html
http://snippets.khromov.se/enable-zlib-compression-in-sshd-on-centos/
nano /etc/ssh/sshd_config
where it says:
# What ports, IPs and protocols we listen for Port 22 <---change port to what you need it to be
then save and restart ssh server
References :
http://ubuntuforums.org/showthread.php?t=1591681
Simply adding a password for root is not enough for Ubuntu 14.04 Server.
You also need to edit /etc/ssh/sshd_config, and comment out the following line:
PermitRootLogin without-password
Just below it, add the following line:
PermitRootLogin yes
Then restart SSH:
service ssh restart
References :
http://askubuntu.com/questions/469143/how-to-enable-ssh-root-access-on-ubuntu-14-04