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
$[username]$
Both machines are using the same user account $username$. 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$ 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?
$[texteditor]$
mkdir -p ~/.ssh && chmod 0700 ~/.ssh/ && touch ~/.ssh/id_ed25519 && chmod 0600 ~/.ssh/id_ed25519 && $texteditor$ ~/.ssh/id_ed25519
then fill your private key
remote server B config public key
Login to machine B, $username$ account.
mkdir -p ~/.ssh && chmod 0700 ~/.ssh/ && touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys && $texteditor$ ~/.ssh/authorized_keys
then add your public key
ssh connect from A to B
Login to machine A, $username$ account.
$[b_hostname]$
ssh $b_hostname$
disable password authentication of server B(optional)
Login to machine B, $username$ account.
sudo $texteditor$ /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$ account.
sudo $texteditor$ /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$ account.
touch ~/.bash_aliases && chmod 0600 ~/.bash_aliases && $texteditor$ ~/.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)
$[texteditor]$
mkdir -p ~/.ssh && chmod 0700 ~/.ssh/ && touch ~/.ssh/id_rsa && chmod 0600 ~/.ssh/id_rsa && $texteditor$ ~/.ssh/id_rsa
then fill your private key
remote server B config public key (old)
Login to machine B, $username$ account.
mkdir -p ~/.ssh && chmod 0700 ~/.ssh/ && touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys && $texteditor$ ~/.ssh/authorized_keys