Script to set up ssh login access

Moderators: Gully, peteru

Post Reply
prl
Wizard God
Posts: 32703
Joined: Tue Sep 04, 2007 13:49
Location: Canberra; Black Mountain Tower transmitters

Script to set up ssh login access

Post by prl » Fri Jul 05, 2019 18:00

A script to set up ssh login access via public key without needing to allow access by password first.

Copy your ssh config files for the Beyonwiz (authorized_keys, config, etc) into directory ssh (or any other name, but preferably not .ssh) onto a disk that your Beyonwiz can access (internal hard drive, thumb drive, network share, etc), put this script into the ssh directory. Then connect the drive if necessary, and run the script using MENU>Files / Sources.

You should then have your ssh access set up. The script itself won't be left in your /home/root/.ssh directory.

If there was already a .ssh directory installed, the script will replace it completely, so you can use the script to allow access even if the box has an ssh public key that you don't have the private key for.

It can be changed to install the .ssh files for other users by editing the HOME variable in the script.

Script contents:

Code: Select all

#!/bin/sh

DIR=`dirname $0`
SCRIPT=`basename $0`
HOME=/home/root

rm -rf "$HOME"/.ssh
cp -a "$DIR" "$HOME/.ssh"
chmod 700 "$HOME"/.ssh
chmod 644 "$HOME"/.ssh/*
rm "$HOME"/.ssh/"$SCRIPT"
The script is designed primarily to be run from File Commander (MENU>Files / Sources), but it it can be run from the commandline provided it's run with the path of the script, and not by finding the script via the shell PATH variable. The script is intended to be used to allow network access to the commandline whan you don't have that access already, so I don't regard that as a bug, even if you do ;)
Attachments
install-ssh.sh
(186 Bytes) Downloaded 76 times
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV

Grumpy_Geoff
Uber Wizard
Posts: 6490
Joined: Thu Mar 05, 2009 22:54
Location: Perth

Re: Script to set up ssh login access

Post by Grumpy_Geoff » Fri Jul 05, 2019 18:50

A not too-dissimilar alternative I've previously used is to put the ssh key on a thumb drive and use File Commander actions to create the /home/root/.ssh directory, copy the ssh key, and do the chmods. This didn't require command line access.

User avatar
peteru
Uber Wizard
Posts: 9735
Joined: Tue Jun 12, 2007 23:06
Location: Sydney, Australia
Contact:

Re: Script to set up ssh login access

Post by peteru » Fri Jul 05, 2019 19:07

You really only ever need to set up the keys once and then backup the config.

"Beauty lies in the hands of the beer holder."
Blog.

prl
Wizard God
Posts: 32703
Joined: Tue Sep 04, 2007 13:49
Location: Canberra; Black Mountain Tower transmitters

Re: Script to set up ssh login access

Post by prl » Fri Jul 05, 2019 19:24

peteru wrote:
Fri Jul 05, 2019 19:07
You really only ever need to set up the keys once and then backup the config.
Except when, why I don't know, .ssh doesn't get backed up.
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV

User avatar
MrQuade
Uber Wizard
Posts: 11844
Joined: Sun Jun 24, 2007 13:40
Location: Perth

Re: Script to set up ssh login access

Post by MrQuade » Fri Jul 05, 2019 20:54

prl wrote:
Fri Jul 05, 2019 19:24
Except when, why I don't know, .ssh doesn't get backed up.
That folder was added to the standard list of backed up locations wasn't it?
Logitech Harmony Ultimate+Elite RCs
Beyonwiz T2/3/U4/V2, DP-S1 PVRs
Denon AVR-X3400h, LG OLED65C7T TV
QNAP TS-410 NAS, Centos File Server (Hosted under KVM)
Ubiquiti UniFi Managed LAN/WLAN, Draytek Vigor130/Asus RT-AC86U Internet
Pixel 4,5&6, iPad 3 Mobile Devices

prl
Wizard God
Posts: 32703
Joined: Tue Sep 04, 2007 13:49
Location: Canberra; Black Mountain Tower transmitters

Re: Script to set up ssh login access

Post by prl » Fri Jul 05, 2019 21:12

MrQuade wrote:
Fri Jul 05, 2019 20:54
prl wrote:
Fri Jul 05, 2019 19:24
Except when, why I don't know, .ssh doesn't get backed up.
That folder was added to the standard list of backed up locations wasn't it?

Yes, it was, but someone switched mine off sometime.

And every now and then I need to do a clean USB update.
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV

Post Reply

Return to “FAQs, Tips & How to Guides”