LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 09-09-2017, 07:16 AM   #16
jamtat
Member
 
Registered: Oct 2004
Distribution: Debian/Ubuntu, Arch, Gentoo, Void
Posts: 138

Original Poster
Rep: Reputation: 24

I did a write-up on setting up passwordless ssh negotiation and was going to post it in this thread. But, as may be evident from reading the thread, it turns out I was functioning under some misconceptions that would have resulted, were I to have posted that original write-up, in the promotion of certain erroneous conceptions concerning the task at hand. So what I've decided to do is to provide a link to a write-up someone else did, one that offers a pretty good explanation, with examples, of setting up passwordless ssh negotiation. I then offer some of my own observations on performing this task and suggest a few of what seem to me advisable modifications. Hence, the following.

https://www.tecmint.com/ssh-password...-5-easy-steps/ provides a pretty good guide for setting up truly passwordless ("truly passwordless" meaning you are not prompted to enter any passphrase) ssh negotiation that even us dimwits should be able easily to follow. I should mention that the method described there is frowned upon by computer security proponents. As I understand it, it's frowned upon because the resulting private key that resides on your computer will not be encrypted because you did not protect it with a passphrase when the key was created--see step 1. b. of that tutorial ("empty passphrase"). Meaning that anyone who can get access to your files can simply cat your private key to a file or to stdout, thereby enabling them to steal it and compromise the security having a key pair is supposed to provide. I would only add to those directives that, if you've already generated a key pair and encrypted it with a passphase, then to get the truly passwordless method described there to work, you'll need to remove the passphrase by issuing a command like ssh-keygen -p /path/to/private/key.

If your dimwittery does not extend too far into the realm of computer encryption and you share the security concerns of those who recommend against creating keys that are unprotected by a passphrase, you should protect your keys with a passphrase and use a utility like keychain so as to set up what I would characterize as semi-passwordless ssh negotiation. Using that tool, you will need to enter the passphrase you used to encrypt your private key only once each session (for most of us, that will mean each time you boot your computer). This is what I did for my systems, adding a line something like
Code:
eval $(keychain --eval --quiet id_ed25519 id_rsa ~/.keys/my_custom_key)
to the appropriate file (.bashrc or .bash_profile, depending on distro) as advised on the Arch wiki (see https://wiki.archlinux.org/index.php/SSH_keys#Keychain)

The only other thing I would add here is some information on how I set this up on my little LAN, where I am often ssh'ing from one or other of 3 computers into another on the same LAN. For my scheme, I created on each computer keys that were alternately named--according to host name in my case. I also took the additional crucial step of crafting appropriate .ssh/config files on each machine so as to make initial set up and, later, initiation of sessions, more comprehensible.

In order to do that, when I was asked for a name and location for each key pair I was generating on the different machines, I specified a more identifiable name than the default (id_rsa was the default in my case)--for example involving a host name such as machine1, as in /home/user/.ssh/machine1.rsa. Be aware that, if you use a name other than the default, you will need to either initiate your ssh session using the -i switch and stipulating the full path to the alternately-named private key, or you will need to edit your .ssh/config file to indicate the path. In the example I've just provided, the public key that needs to be copied to the remote server will be named machine1.rsa.pub.

Since I have 3 or 4 machines from/to which I need to ssh on a regular basis, and since the difficulties I have with conceptualizing client/server scenarios are further exacerbated with the introduction of the encryption element, I prefer to name my keys in ways that help me to better distinguish which keys relate to which machine. Thus, I would want to end up with key pairs named something like home.rsa/home.rsa.pub on one machine, office.rsa/office.rsa.pub on another, laptop.rsa/laptop.rsa.pub on yet another, and so forth. Since issuing these modified names from the command line in the form ssh -i ~/.ssh/office.rsa user@remote is rather unwieldy, I modified/created the .ssh/config file on each machine in order to better automate the negotiation process. That can be done in the following way (note that the following step is necessary in order for this type of semi-passwordless ssh session to be initiated: the system must be able to find the renamed id_rsa file or you will be stuck with username/password logins or, should you have disable those types of logins, might even wind up being locked out of your remote system).

On the local machine--in this example, my laptop--using a series of commands from within the .ssh directory such as
Code:
echo "Host office" >> config
echo "Hostname office" >> config
echo "IdentityFile ~/.ssh/laptop.rsa" >> config
allowed me, once I had copied over laptop.rsa.pub to the remote machine (host name "office") and cat'd it to ~/.ssh/authorized_keys on that remote computer, to ssh to that remote machine by simply issuing
Code:
ssh user@remote
Or even just
Code:
ssh remote
, should my username on the remote machine be the same as the username on the local machine. Note further that the IdentityFile being placed in .ssh/config is the one located on the local machine.

I apologize. I really wanted to make this guide as simple as possible--so that even I could, on a quick skim, readily understand and implement it. But the matters touched on are so complex and recondite that what I've come up with is the simplest presentation I could manage at the moment.

Last edited by jamtat; 09-09-2017 at 11:22 AM.
 
Old 06-29-2022, 10:32 AM   #17
jamtat
Member
 
Registered: Oct 2004
Distribution: Debian/Ubuntu, Arch, Gentoo, Void
Posts: 138

Original Poster
Rep: Reputation: 24
I found a great explanation of the basics of key pair authentication and wanted to post a link to it in this thread. It's the best one I've found so far. See the keychain article for links to that 3-part series at https://www.funtoo.org/Funtoo:Keychain
 
Old 06-29-2022, 11:51 AM   #18
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
TLDR.

On a typical distro, there are just two steps. Turn off passwordless logins, and set your SSH password to be the same as your login password. Sometimes you need to put "AddKeysToAgent yes" in ~/.ssh/config, but usually you don't even need to do that.

Last edited by dugan; 06-29-2022 at 02:25 PM.
 
Old 06-29-2022, 07:27 PM   #19
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
I find ssh "passwordless logins" to be very convenient, but I always place them behind a digital-certificate based VPN. (Usually, "OpenVPN.") I never want "the Internet at large" to even be able to discover that a "sshd" service is out there, let alone reach it. You must pass through the VPN first.

I routinely use "OpenVPN" with the tls-auth feature, of course using individually-issued digital certificates. Which basically means that a "malicious 'bot'" cannot even find the front door. They never get to discover, let alone challenge, my second-tier "sshd" defenses. Whereas, authorized users are scarcely delayed.

Last edited by sundialsvcs; 06-29-2022 at 07:32 PM.
 
Old 06-30-2022, 02:32 AM   #20
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
As others already said, passwordless ssh is well documented in various places on the WWW. I always go back to this wiki when I need a refresher.
 
Old 07-01-2022, 10:39 AM   #21
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
The problem with putting ssh "on the front line" is that every "bot" on the Internet will discover its existence and begin to hammer it relentlessly. Which soaks up time and resources that are better spent elsewhere. An OpenVPN "outer moat with a secret tls-auth drawbridge" is extremely effective at putting a 100% stop to that. "Unauthorized access attempts" simply ... cease. You can't attack anything if you can't even find it ...

Authorized users find and cross the bridge with nary a pause, where they are then able to see and use ssh. "Just click on the icon at the top of your screen and wait five seconds until it turns dark, indicating that the VPN tunnel is now connected." And since you are using individually-issued certificates, it's no problem when someone leaves the company (or if a laptop is stolen at the airport). Certs can also be password-protected (encrypted).

Your server's security-logs will thank you ...

Last edited by sundialsvcs; 07-01-2022 at 10:51 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sftp asking for password authentication but my public key is passwordless slepthien Linux - Newbie 9 03-07-2014 08:49 AM
SSH skips public key authentication for a key, but works with another key simopal6 Linux - General 1 07-06-2011 08:33 AM
LXer: Setting up public key authentication for SSH LXer Syndicated Linux News 0 01-24-2011 02:50 AM
SSH with passwordless public/private key not working on another account on server infocom Linux - Server 14 12-27-2010 05:09 AM
public key authentication for ssh - linux client to winxp server cdaaawg General 6 03-10-2008 04:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration