CheatSheet: How access a remote machine with a SSH key?

This is a simple cheat sheet: How access a remote machine with a SSH key?

Step 1: Copy your private SSH key to your local machine.

export RSA_FILE=ssh-private-key
mv $RSA_FILE ~/.ssh
chmod 400 ~/.ssh/$RSA_FILE

Step 2 (Optional): Add public key.

export PUBLIC_KEY=ssh-XXXX YYYYYY
cd ~/.ssh/
eval $(ssh-agent -s)
ssh-add ${PUBLIC_KEY}

Step 3 (Optional): Edit known_hosts.

nano ~/.ssh/known_hosts

Step 4 (Optional): Update your `~/.ssh/config` file

# My Machine
Host 149.XX.XXX.XX
  HostName 149.XX.XXX.XX
  IdentityFile ~/.ssh/my_private_key
  User root

Step 5: Access the remote machine from your local computer.

export FLOATING_IP=YOUR_REMOTE_IP
export REMOTE_USER=ubuntu         
ssh -i ~/.ssh/${RSA_FILE} ${REMOTE_USER}@${FLOATING_IP}

Step 6: Use “secure copy” to copy your files from the local to the remote machine.

export FLOATING_IP=YOUR_REMOTE_IP
export REMOTE_USER=ubuntu
export DESTINATION_PATH=/home/
scp -i ~/.ssh/$RSA_FILE -rp .env ${REMOTE_USER}@${FLOATING_IP}:${DESTINATION_PATH}

These are two blog posts in this context which may be helpful in this context:


I hope this was useful for you and let’s see what’s next?

Greetings,

Thomas

#sshkey, #ssh, #securecopy, #cheatsheet

One thought on “CheatSheet: How access a remote machine with a SSH key?

Add yours

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑