[LINUX] Log in to Raspberry PI with ssh without password (key authentication)

motivation

If you use Raspberry Pi like a server, you will have more chances to log in with ssh. It is a story that I set up key authentication because it is troublesome to type the password every time.

I think it's the basic method of Linux, so I can find out as many as I can, but I'll leave it here because it's annoying to check it every time.

Creating authorized_keys

Create `` `~ / .ssh``` on raspberry pi (only if not already)

$ mkdir ~/.ssh
$ chmod 700 ~/.ssh

Creating authorized_keys

$ touch ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys

Creating a public key

On your own PC (pc on the side that hits the login command)

$ ssh-keygen -t rsa

You will be asked a lot, but for the time being, all are Default (hold down the Enter Key)

Below, the private key and public key are created.

$ ls ~/.ssh
id_rsa  id_rsa.pub

id_rsa.Transfer pub to raspberry pi.


 Note: If there is a file with the same name on the Raspberry Pi, it makes no sense, and in the worst case it will be overwritten, so it is recommended to rename and transfer it. I used the `` `* .imac``` because it is the key to the imac.

```bash
$ scp id_rsa.pub [email protected]:~/.ssh/id_rsa.pub.imac

Public key registration

Go back to the raspberry pi and work on `` `~ / .ssh```. If the transfer is successful, the files will be placed as shown below.

~/.ssh $ ls
authorized_key id_rsa.pub.imac

id_rsa.pub.The contents of imac are authorized_Register in keys.




```bash
cat id_rsa.pub.imac >> ~/.ssh/authorized_keys

Complete

Now you won't be asked for your password the next time you log in with ssh.

Recommended Posts

Log in to Raspberry PI with ssh without password (key authentication)
[Simple procedure] To log in to ssh without a password
Log in to the remote server with SSH
How to set up public key authentication in ssh
Stop SSH password authentication and switch to key authentication completely
Set public key authentication when connecting with SSH in Teraterm
Ssh login with public key authentication quickly
Voice authentication & transcription with Raspberry Pi 3 x Julius x Watson (Speech to Text)
Log in to Yahoo Business with Selenium Python
Easily log in to AWS with multiple accounts
Connect to MySQL with Python on Raspberry Pi
Edit and debug the code in the Raspberry Pi with VS Code's SSH connection feature
Easy IoT to start with Raspberry Pi and MESH
[Ansible] How to use SSH password authentication when executing ansible
GPGPU with Raspberry Pi
Try to visualize the room with Raspberry Pi, part 1
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
DigitalSignage with Raspberry Pi
[Amazon Linux 2] Change from public key authentication to password authentication
Make a note of what you want to do in the future with Raspberry Pi
It was great to edit the Python file in the Raspberry Pi with Atom's remote function
Easy introduction to home hack with Raspberry Pi and discord.py
Update Python for Raspberry Pi to 3.7 or later with pyenv
Basic authentication with an encrypted password (.htpasswd) in bottle with python
How to log in automatically like 1Password from the CLI
Cast json with key CamelCase to snake_case class in pydantic
I can't log in to the admin page with Django3
Change the message displayed when logging in to Raspberry Pi
Use ssh with private key public key authentication. Connect from wan.
How to log in to AtCoder with Python and submit automatically
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
Introduced python3-OpenCV3 to Raspberry Pi
I talked to Raspberry Pi
Introducing PyMySQL to raspberry pi3
Ubuntu (18.04.3) SSH edition Key authentication
Getting Started with Heroku-Viewing Hello World in Python Django with Raspberry PI 3
I tried to automate the watering of the planter with Raspberry Pi
I made a web server with Raspberry Pi to watch anime
Building LAMP with Linux MINT Cannot log in with mysql root password
I tried to log in to twitter automatically with selenium (RPA, scraping)
Periodically log the value of Omron environment sensor with Raspberry Pi
Run Polyglot on Raspberry Pi to perform morphological analysis in English
How to put OpenCV in Raspberry Pi and easily collect images of face detection results with Python
Port FreeRTOS to Raspberry Pi 4B
[Raspberry Pi] Stepping motor control with Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Servo motor control with Raspberry Pi
Serial communication with Raspberry Pi + PySerial
Output from Raspberry Pi to Line
OS setup with Raspberry Pi Imager
Try L Chika with raspberry pi
VPN server construction with Raspberry Pi
Try moving 3 servos with Raspberry Pi
Password generation in texto with python
Using a webcam with Raspberry Pi
How to log in to Docker + NGINX
[Raspberry Pi] Changed Python default to Python3
[Linux setting series] How to set public key authentication / ssh-keygen / ssh key / authorized_keys
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Note: I want to do home automation with Home Assistant + Raspberry Pi + sensor # 1
Use python on Raspberry Pi 3 to light the LED with switch control!