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 -t ed25519 -C "roger@home"
cat ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
- id_ed25519 is the private key that should never share with others.
- id_ed25519.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_ed25519 && chmod 0600 ~/.ssh/id_ed25519 && {{ texteditor.value }} ~/.ssh/id_ed25519
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
generate ssh keys file (old)
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? (old)
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 (old)
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