Enter ssh password automatically using bash
#!/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
#!/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 enable the keep alive system-wide (root access required), edit /etc/ssh/ssh_config
;
to set the settings for just your user, edit ~/.ssh/config
(create the file if it doesn’t exist). Insert the following:
Host * ServerAliveInterval 300 ServerAliveCountMax 2
You can also make your OpenSSH server keep alive all connections with clients by adding the following to /etc/ssh/sshd_config
:
ClientAliveInterval 300 ClientAliveCountMax 2
References
https://patrickmn.com/aside/how-to-keep-alive-ssh-sessions/
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