1. MagicESP
  2. Ubuntu Server 18.04
  3. SSH Connect from Ubuntu

SSH Connect from Ubuntu

connect from local machine A (also could be a remote server) to remote server B is quite easy using ssh keys file.

Prerequisite

Both machines are using the same user account {{ username.value }}. If not, Create ubuntu account first. Always use the same username will make life much easier.

Local Machine A config private key

Login to machine A, {{ username.value }} account.

generate ssh keys file

ssh-keygen
cat ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub
  • id_rsa is the private key that should never share with others.
  • id_rsa.pub is the public key that need to tell other severs.

already have the private key?

mkdir -p ~/.ssh && chmod 0700 ~/.ssh/ && touch ~/.ssh/id_rsa && chmod 0600 ~/.ssh/id_rsa && {{ texteditor.value }} ~/.ssh/id_rsa

then fill your private key

remote server B config public key

Login to machine B, {{ username.value }} account.

mkdir -p ~/.ssh && chmod 0700 ~/.ssh/ && touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys && {{ texteditor.value }} ~/.ssh/authorized_keys

then add your public key

ssh connect from A to B

Login to machine A, {{ username.value }} account.

ssh {{ b_hostname.value }}

disable password authentication of server B(optional)

Login to machine B, {{ username.value }} account.

sudo {{ texteditor.value }} /etc/ssh/sshd_config
PasswordAuthentication no
sudo /etc/init.d/ssh restart

disable direct root login of server B(optional)

Login to machine B, {{ username.value }} account.

sudo {{ texteditor.value }} /etc/ssh/sshd_config
PermitRootLogin no
sudo /etc/init.d/ssh restart

run script when user login in server B(optional)

Login to machine B, {{ username.value }} account.

touch ~/.bash_aliases && chmod 0600 ~/.bash_aliases && {{ texteditor.value }} ~/.bash_aliases