Page 1 of 1

Headless login practices?

Posted: Sun Feb 23, 2020 3:33 am
by Disbursed
Please tell me if I'm misunderstanding something.

It seems that if I want to log in headless from my Mac, for instance, I'd want to do " ssh [email protected]<IP address>, " but if the router is serving DHCP, I'll have to determine the new IP address each session. It seems that one way to always have the IP address available is to set the Pi as a static IP address on the router.

Is there another way, like setting some kind of alias so that the function might be " ssh [email protected] " so that it can always find the Pi?

Maybe I'm missing something.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 3:44 am
by ejolson
Disbursed wrote:
Sun Feb 23, 2020 3:33 am
Please tell me if I'm misunderstanding something.

It seems that if I want to log in headless from my Mac, for instance, I'd want to do " ssh [email protected]<IP address>, " but if the router is serving DHCP, I'll have to determine the new IP address each session. It seems that one way to always have the IP address available is to set the Pi as a static IP address on the router.

Is there another way, like setting some kind of alias so that the function might be " ssh [email protected] " so that it can always find the Pi?

Maybe I'm missing something.
Most modern routers can be set to serve the same IP number based on MAC to a particular Pi each time that Pi requests a lease. Otherwise, the easiest solution is to use a static IP numbers outside the range of the dynamically assigned ones.

There are other ways of broadcasting hostnames about so that machines know what is what which sometime even work. I've never troubled to learn about them or set them up, but perhaps someone else can provide information.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 5:28 am
by Disbursed
Static IP it is, then. Thanks.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 8:19 am
by jahboater
To set the static IP address from the Pi, edit:

/etc/dhcpcd.conf

it has examples.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 8:28 am
by krgnl
There is a super simple solution that I think will wor in your setting. But first, best practice is to set a static ip in the router. I would refrain from setting a static ip on the pi, because you might you might get conflicts in your network.

Super simple solution:

ssh [email protected]

This works because of Bonjour/mDNS

See https://en.wikipedia.org/wiki/.local

Re: Headless login practices?

Posted: Sun Feb 23, 2020 8:29 am
by B.Goode
Disbursed wrote:
Sun Feb 23, 2020 3:33 am
Please tell me if I'm misunderstanding something.

It seems that if I want to log in headless from my Mac, for instance, I'd want to do " ssh [email protected]<IP address>, " but if the router is serving DHCP, I'll have to determine the new IP address each session. It seems that one way to always have the IP address available is to set the Pi as a static IP address on the router.

Is there another way, like setting some kind of alias so that the function might be " ssh [email protected] " so that it can always find the Pi?

Maybe I'm missing something.


Firstly, it is very likely that your RPi will not have a new IP address for each session.

Second, the relevant Raspberry Pi documentation refers to mDNS which may provide the sort of alias you seek. https://www.raspberrypi.org/documentati ... ddress.md


But I would still advocate a server allocated DHCP solution as already suggested.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 9:55 am
by GlowInTheDark
What is wrong with just:
(where, of course, "myraspberry" is whatever hostname you have given to the Pi)

That should work with most routers. Why bother with figuring out the numeric IP address?

Note that sometimes, you do need to append ".local" to the name, but in general, you'll figure it out.

Also, given that you mention using a Mac, you can put stuff in the file /etc/hosts on the Mac. This is crude, but it does provide the sort of "alias" functionality that you mention.

Note that sometimes, like say, when you have to reboot your router (say, after a power outage), things will stop working for a while. Usually, just letting things sit overnight fixes everything. So, patience can be a virtue.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 12:35 pm
by epoch1970
Raspbian includes zeroconf and mDNS, provided by the Avahi software package.
A Mac does as well, except not via Avahi.

zeroconf gives machines an address on a specific network so that they can interact even in case there is no DHCP server available.
If a DHCP server delivers an address or if a static IP is defined, the zeroconf address is discarded (in general).

mDNS gives machines the ability to lookup other machines by name, in the ".local" domain, even in case there is no DNS server available. The target machine responds with its current IP address.

According to the situation, "ping rpi.local" might target IP 169.254.18.10 (a zeroconf IP address) or IP 192.168.1.2 (a DHCP or static IP address) according to the current IP setup on machine "rpi".

So. From a Mac, the best practice is: a. change nothing to the Pi, b. change nothing to the DHCP server (if any), c. type "ssh [email protected]_of_pi.local" (and yes, the full name including .local is mandatory otherwise you're not looking up using mDNS, but DNS and hosts file.)

Re: Headless login practices?

Posted: Sun Feb 23, 2020 1:30 pm
by GlowInTheDark
(and yes, the full name including .local is sometimes necessary)
FIFY

As I said in my previous post - sometimes you need the .local, if your router's DNS is not working correctly at the moment. Usually, this problem goes away in a day or two.

But the point is, as always: Whatever works.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 3:12 pm
by Disbursed
Thank you, mDNS is the functionality I was searching for - I appreciate your pointing it out.

Re: Headless login practices?

Posted: Sun Feb 23, 2020 5:38 pm
by Disbursed
I can successfully ssh using
ssh [email protected]<ip address> without needing a password (I haven't removed it yet because I'll need it to add another computer). It works fine.

But when I try the ".local" formulation
ssh raspberrypi.local
it demands my local password. It won't accept my pi password and I don't have a password on my keys stored on the Mac - I have pressed <Enter> with nothing added. It continues to say "Permission denied, please try again."

edit: ping -c 2 raspberrypi.local works.

Edit: At one point it did read, "Permission denied (publickey,password)."

I have run " ssh-add " and that works.

Any ideas?

Re: Headless login practices?

Posted: Sun Feb 23, 2020 5:57 pm
by epoch1970
Add the user name you want to login as on the pi
ssh [email protected]

If you omit [email protected] ssh will use your current login name on the Mac. So unless your account on the Mac is “pi” that won’t work...

Re: Headless login practices?

Posted: Sun Feb 23, 2020 6:26 pm
by Disbursed
epoch1970 wrote:
Sun Feb 23, 2020 5:57 pm
Add the user name you want to login as on the pi
ssh [email protected]

If you omit [email protected] ssh will use your current login name on the Mac. So unless your account on the Mac is “pi” that won’t work...
That sounds like the right direction. Can you be a little more verbose, please?

Running "ssh [email protected]" gave me the following: "ssh: Could not resolve hostname local: nodename nor servname provided, or not known"

Is it: ssh [email protected]?

Re: Headless login practices?

Posted: Sun Feb 23, 2020 6:59 pm
by kerry_s
if you haven't changed it, the default host name is raspberrypi: ssh [email protected]

i use the host name to login that doesn't change. so for my pi-hole i just use: ssh [email protected]

Re: Headless login practices?

Posted: Sun Feb 23, 2020 7:15 pm
by Disbursed
kerry_s wrote:
Sun Feb 23, 2020 6:59 pm
if you haven't changed it, the default host name is raspberrypi: ssh [email protected]

i use the host name to login that doesn't change. so for my pi-hole i just use: ssh [email protected]
Thanks, I just found it: https://gordonlesti.com/change-default- ... pberry-pi/
I appreciate it.