I newer Used
PAM and I newer edited Default «/etc/ssh/sshd_config». All (almost All) Changes can Be Provided via Main Configuration File «/etc/rc.conf.local» (or «/etc/rc.conf», if You want). Note,
If You make a Mistake in This File with Quotation Marks, for Examlpe,
System Will Not Start!
The Best Way is to Put Your <Root Public Key> into «~root/.ssh/authorized_keys» File during the Last Stage of FreeBSD Installation Process, when BSDInstall suggestes You to Make Final Changes in the System:
Bash:
mkdir -p -v -m "500" ~root/.ssh && printf "<Public Key>\n" >> ~root/.ssh/authorized_keys && chmod "400" ~root/.ssh/authorized_keys
Than Edit Config File with «ee "/etc/rc.conf.local"» and add some Parameters for
SSHD:
INI:
sshd_flags="${sshd_flags%[[:space:]]}${sshd_flags:+" "}-o Port=\"22222\" -o PerMitRootLogIn=\"ProhiBit-PassWord\" -o PassWordAuthentication=\"No\" -o ChallengeResponseAuthentication=\"No\" -o GSSAPIAuthentication=\"No\" -o UsePAM=\"No\" -o ClientAliveInterval=\"360\" -o ClientAliveCountMax=\"6\""
to EnAble Root with the Public Key Only, Not Using PassWord and Move SSHD to UnStandart Port (PuTTY & Far Manager Must be Configured to use This Port Number as well).
But, as I understand,
You did Not Do This during Install, so:
0. GeneRate a Key Pair (on Another Machine, from which You will Access to this Box), like «ssh-keygen -t "RSA" -b "16384" -C "RSA Key 16384 Bits for Root on the FireWall Box" -N "" -f ~/.ssh/Box-Root-RSA-16384 -v» or by PuTTYgen with this Parameters. Long GeneRation, but It Is for the «
Root» on a Machine, Looking Out to the InterNet, so Sit and Wait! Also make Sure, SSH/PuTTY Version is «
Up to Date» — Developers do not «Sleep».
1. If You Can Access (SomeHow? It is
Really HeadLess?) Your FileSystem, Make «Temporary» (before
Correct SetUp
↑, Just to Connect Once to the Machine) «/etc/rc.conf.local» with this Line: «sshd_flags=" -o PerMitRootLogIn=Yes"» and ReStArt SSHD: «service "sshd" restart» or ReBoot Your «Box».
2. Connect to Your Box (SSH, PuTTY, …), Using Name «root» and PassWord, entered (twice?) during SetUp Process.
3. Make Settings, described Before to SetUp Key-Based Authorization SSH-2 and
DisAble «PerMitRootLogIn=Yes», as a Very Bad «Temporary» Idea!
4. Make «~/.ssh/config» Files for Accounts with SSH-Access to This Server — It's extremely Convenient!
C#:
match Host "Box,Box.DoMaIn.Org" # Aliases, can be Any, You Like…
HostName "Box.DoMaIn.Org" # Real DNS-Name of the Server or IP-Address.
# Generally, RePlacing 22 Port with a «Non—Standard» Value Is Not a very Reliable Protection… But if You are Tired of Collecting 300K+ Errors per Hour from «/var/log/auth.log» and «/var/log/messages», then This Measure Helps…
Port "22222" # Non-Standard Port, Specified in the Parameter String for SSHD («sshd_flags="${sshd_flags%[[:space:]]}${sshd_flags:+" "}-o Port=\"22222\" -o PerMitRootLogIn=\"ProhiBit-PassWord\"…"» at «/etc/rc.conf.local» in the Case of FreeBSD).
User "SuperPuperRoot"
IdentityFile "~/.ssh/Box-Root-ED25519" # A «Fast-Acting» Secret Key for Connections from «Trusted» and Verified Addresses. The List Of Addresses Is Limited By The String «From="AAAA:BBBB:CCCC:DDDD::?,123.456.789.012,TrustedGate.Org" ssh-ed25519 …PublicKey… …Comment…» in the File «~root/.ssh/authorized_keys» on the Server.
IdentityFile "~/.ssh/Box-Root-RSA-16384" # A «ReliAble» Secret Key for Connections from «All Other» Hosts. There is no «From=…» Construction in the «~root/.ssh/authorized_keys» File before It, or the Rules in It Are «More General».
ConnectTimeout "360"