Sitemap

Simple Command for SSH

Experiment Note

1 min readJul 4, 2021

--

If you don’t have rsa key, please generate with this command. You will get rsa private key and public key into $HOME/.ssh/id_rsa, but you can custom path when you run this command.

ssh-keygen -t rsa -b <bit-size> -C "your comment"
e.g. ssh-keygen -t rsa -b 4096 -C "nattakit.boonyang@gmail.com"

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/kk/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in a.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
SHA256:sUuJUAHAStKscOiH70b3Tv4QQgWa8A/k0g1PMRx0/ac nattakit.boonyang@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
| *.++O*+. |
|+.@ Bo+ . |
|==.B.+ . . |
|oo..+. . + . . |
| o o..S o |
| o ..... E |
| o . .o. |
| o o.. |
| . .o.. |
+----[SHA256]-----+

Copy your key into a server that you need to access without password

ssh-copy-id -i ~/.ssh/id_rsa user@host -p <custom port>
e.g. ssh-copy-id -i ~/.ssh/id_rsa ubuntu@example.com

Get NB’s stories in your inbox

Join Medium for free to get updates from this writer.

Enable this line on your server for access by RSA and restart ssh server

sudo nano /etc/ssh/sshd_config
PubkeyAuthentication yes # add or uncomment this line
sudo /etc/init.d/ssh restart

Create or edit ~/.ssh/config for apply rsa key to specific hostname

sudo nano ~/.ssh/configHost <hostname or ip address>
IdentityFile ~/.ssh/id_rsa

Try to connect into server

ssh user@host -p <custom port>
e.g. ssh ubuntu@example.com

--

--