0

I am trying to SSH into my Raspberry Pi 4 Model B for the first time. I've successfully installed the Raspberry OS using the UI configuration tool from the official website and boot loaded and SSH server is running my desktop PC can see and try to login via SSH, here's the error:

Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\emre/.ssh/id_rsa): ~/.ssh/pi_rsa
PS D:\vscode\discord-poker-in-rust> ssh -v emre@raspberrypi                                                      
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Reading configuration data C:\\Users\\emre/.ssh/config
debug1: Connecting to raspberrypi [192.168.1.6] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\emre/.ssh/id_rsa type 0
debug1: identity file C:\\Users\\emre/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\emre/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\emre/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\emre/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\emre/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\emre/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\emre/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\emre/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\emre/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.4p1 Raspbian-5+deb11u1
debug1: match: OpenSSH_8.4p1 Raspbian-5+deb11u1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to raspberrypi:22 as 'emre'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
Connection closed by 192.168.1.6 port 22

I've this additional code that gets run somehow (I don't know the exact process) as a setup script after the booting:

#!/bin/bash

set +e

CURRENT_HOSTNAME=`cat /etc/hostname | tr -d " \t\n\r"`
if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
   /usr/lib/raspberrypi-sys-mods/imager_custom set_hostname raspberrypi
else
   echo raspberrypi >/etc/hostname
   sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\traspberrypi/g" /etc/hosts
fi
FIRSTUSER=`getent passwd 1000 | cut -d: -f1`
FIRSTUSERHOME=`getent passwd 1000 | cut -d: -f6`
if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
   /usr/lib/raspberrypi-sys-mods/imager_custom enable_ssh
else
   systemctl enable ssh
fi
if [ -f /usr/lib/userconf-pi/userconf ]; then
   /usr/lib/userconf-pi/userconf 'emre' '$5$myPlErvvCt$yVK2WdncWGT268stRoCuS1u1R/pj1RqvrT2Gj5Z9tQ5'
else
   echo "$FIRSTUSER:"'$5$myPlErvvCt$yVK2WdncWGT268stRoCuS1u1R/pj1RqvrT2Gj5Z9tQ5' | chpasswd -e
   if [ "$FIRSTUSER" != "emre" ]; then
      usermod -l "emre" "$FIRSTUSER"
      usermod -m -d "/home/emre" "emre"
      groupmod -n "emre" "$FIRSTUSER"
      if grep -q "^autologin-user=" /etc/lightdm/lightdm.conf ; then
         sed /etc/lightdm/lightdm.conf -i -e "s/^autologin-user=.*/autologin-user=emre/"
      fi
      if [ -f /etc/systemd/system/[email protected]/autologin.conf ]; then
         sed /etc/systemd/system/[email protected]/autologin.conf -i -e "s/$FIRSTUSER/emre/"
      fi
      if [ -f /etc/sudoers.d/010_pi-nopasswd ]; then
         sed -i "s/^$FIRSTUSER /emre /" /etc/sudoers.d/010_pi-nopasswd
      fi
   fi
fi
if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
   /usr/lib/raspberrypi-sys-mods/imager_custom set_wlan 'ASUS' '807b2d874d8106494a8b36e208cf5f58e7b998c82184225bfab1c407c69ab59a' 'TR'
else
cat >/etc/wpa_supplicant/wpa_supplicant.conf <<'WPAEOF'
country=TR
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
ap_scan=1

update_config=1
network={
    ssid="ASUS"
    psk=807b2d874d8106494a8b36e208cf5f58e7b998c82184225bfab1c407c69ab59a
}

WPAEOF
   chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf
   rfkill unblock wifi
   for filename in /var/lib/systemd/rfkill/*:wlan ; do
       echo 0 > $filename
   done
fi
if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
   /usr/lib/raspberrypi-sys-mods/imager_custom set_keymap 'us'
   /usr/lib/raspberrypi-sys-mods/imager_custom set_timezone 'Europe/Istanbul'
else
   rm -f /etc/localtime
   echo "Europe/Istanbul" >/etc/timezone
   dpkg-reconfigure -f noninteractive tzdata
cat >/etc/default/keyboard <<'KBEOF'
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""

KBEOF
   dpkg-reconfigure -f noninteractive keyboard-configuration
fi
rm -f /boot/firstrun.sh
sed -i 's| systemd.run.*||g' /boot/cmdline.txt
exit 0

I've asked various sources, but no one can help me:

Here's the full command I used to login to my Raspberry Pi ssh -v emre@raspberrypi

Note that I am trying to do a headless setup, I don't have a keyboard or monitor to plug into the Raspberry Pi. Thank you.

3
  • Did you set up your public key as an authorized key on the Raspberry Pi? Or does the SSHD on the Raspberry Pi allow password authentication? What instructions did you follow to create the setup script? Please edit your question to add this information.
    – Bodo
    Aug 10 at 18:26
  • You used the Raspberry Pi imager. What advanced options did you set?
    – joan
    Aug 10 at 20:15
  • Sorry guys, it has been resolved somehow, turns out I setup this config as is, then didn't actually load this particular latest settings into Pi. Have tested previously with similar settings though something were off, Now I've did it.
    – eguneys
    Aug 10 at 22:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.