Updated for FortiOS 7.4, 7.6 and 8.0: .pub keys, X.509 certificates, and the hardening that makes key-only admin access real
Executive Summary
FortiGate SSH public key authentication lets an administrator log in to the CLI with a key pair instead of a password. You paste the contents of your .pub file into the admin account, keep the private key on your workstation, and the FortiGate proves you hold that private key on every login without the key ever crossing the wire.
The setup is three lines of CLI. The part most guides skip is what happens around those three lines: the trusted host check, the cipher negotiation, the key match, the signature check, the lockout counter, and the password fallback that stays wide open unless you turn it off. This post walks through each check in order, then hardens every one of them.
| Objective | Replace password logins on the FortiGate CLI with key-based SSH, understand exactly what the FortiGate verifies during that login, and close the gaps that leave a password path open. |
| Target audience | FortiGate administrators, network and security engineers, and anyone automating FortiGate access from scripts, Ansible, or FortiNAC. |
| Tested on | FortiOS 7.4.x, 7.6.x and 8.0.x CLI syntax (version notes called out inline) |
What changed in this update
- Key types: FortiOS accepts RSA, ECDSA (nistp256, nistp384, nistp521) and Ed25519 keys. ECDSA support for admin SSH arrived in 7.0.2. Ed25519 is the default recommendation here.
- Cipher settings moved: from 7.4.4, the
ssh-enc-algo,ssh-kex-algoandssh-mac-algosettings live underconfig system ssh-config, and the oldssh-hostkey-algobecamessh-hsk-algo. - Host key change after upgrade: 7.0.13 and 7.2.6 stopped offering
ssh-rsaas a host key algorithm, so many clients saw a “host identification has changed” warning after the upgrade. Gotcha 3 covers it. - The backup password is still mandatory. Fortinet’s own guidance is to set one even on key-only accounts. Skip it and the account can log in to the GUI with no password at all.
Prerequisites and Architecture
Assumed knowledge: basic FortiOS CLI, what an SSH key pair is, and how to reach the FortiGate console in case you lock yourself out of SSH.
| Component | Lab value | Role |
|---|---|---|
| FortiGate management IP | 10.0.1.1 (mgmt port, allowaccess ssh https) | SSH server, stores the public key |
| Admin workstation | 10.0.10.25 in 10.0.10.0/24 | SSH client, holds the private key |
| Admin account | netops-manny |
Key-based account with a least-privilege profile |
| Key pair | ~/.ssh/fgt_admin_ed25519 and .pub |
Ed25519, passphrase protected |
| Out-of-band access | Serial console | Recovery path, not affected by SSH lockdown |
Warning: Keep a console session or a second logged-in SSH session open the whole time you work through Step 5. Disabling SSH passwords is global and takes effect immediately.
How FortiGate SSH Public Key Authentication Works: The Checks, in Order
When your SSH client connects, the FortiGate runs a sequence of gates. Fail any one of them and you never reach a prompt. Knowing the order tells you exactly where to look when a login fails.
Figure 1: The FortiGate SSH key login check flow

- Interface access. SSH is answered only on interfaces with
sshinallowaccess, on the configuredadmin-ssh-port. Everywhere else the connection is never accepted. - Trusted hosts. The source IP is compared with the account’s
trusthost1totrusthost10entries. A login from a non-trusted address is dropped even with valid credentials. One catch: if any single admin has no trusted hosts, the FortiGate answers SSH from every address, and only the per-account check protects you. - Transport negotiation. Client and FortiGate agree on key exchange, cipher, MAC and host key algorithms from the lists in
config system ssh-config. The FortiGate proves its own identity with its host key, and your client checks that againstknown_hosts. This is the check that stops a fake FortiGate from collecting your login. - Login grace timer. The client has
admin-ssh-grace-timeseconds to finish authenticating (120 by default). Half-open sessions are cut off when it expires. - Method offer. The FortiGate tells the client which methods it accepts:
publickey,passwordby default, orpublickeyalone once you disable SSH passwords. - Key match. The client offers a public key for the username. The FortiGate compares it with
ssh-public-key1,ssh-public-key2andssh-public-key3on that account, and with the public key inside the remote certificate set inssh-certificate. A key that matches nothing is rejected and logged with reasonssh_key_invalid. - Proof of possession. For a matching key, the client signs data that includes the unique hash of this session’s key exchange, using the private key. The FortiGate verifies that signature with the stored public key. The private key never leaves your machine, and a captured signature is useless in any other session.
- Lockout counter. Failed attempts count toward
admin-lockout-threshold(3 by default), and the offending source IP is blocked foradmin-lockout-durationseconds. - Authorization and logging. On success the account’s access profile and VDOM scope are applied and an “Admin login successful” event is written. If the key failed and passwords are still allowed, the client falls back to a password prompt instead.
How it is secured, and where it is not
| Threat | What stops it | Setting |
|---|---|---|
| Password brute force on SSH | No password method offered at all | admin-ssh-password disable |
| Stolen config backup | Only the public key is stored, and it cannot log in by itself | Built in |
| Fake FortiGate / man in the middle | Client verifies the FortiGate host key | known_hosts, ssh-hsk-algo ssh-ed25519 |
| Replay of a captured login | Signature is bound to one session’s exchange hash | Built in |
| Scanning from anywhere | Login accepted only from listed sources | trusthost1 to trusthost10, no SSH on WAN |
| Pre-auth connection floods | Unauthenticated sessions time out fast | admin-ssh-grace-time 30 |
| Crypto downgrade | Only modern algorithms negotiated | config system ssh-config, strong-crypto |
| Stolen laptop | Passphrase on the private key, plus trusted hosts | ssh-keygen -a 100, trusted hosts |
Be honest about the limits. A raw public key never expires and has no revocation list: if a laptop walks away, someone has to remove that key from every FortiGate it was loaded on. Each admin holds at most three keys. Fortinet’s admin documentation lists RSA, ECDSA and Ed25519 key types, with no FIDO2 sk- hardware-backed key types and no option to trust an OpenSSH user CA. If you need expiring credentials and principals, that is the SSH certificate authority model, which today you get in front of the FortiGate (ZTNA SSH access proxy, a bastion) rather than in the admin login itself.
Step-by-Step Implementation
Step 1: Generate the key pair on the workstation
Goal: Create an Ed25519 key pair with a passphrase.
Action: Run ssh-keygen on macOS, Linux, or Windows 10/11 PowerShell (OpenSSH is built in). The -a 100 flag raises the passphrase key-derivation rounds, which makes an offline guess against a stolen key file much slower.
ssh-keygen -t ed25519 -a 100 -C "netops-manny@fgt" -f ~/.ssh/fgt_admin_ed25519
# Print the two fields FortiOS wants: key type and key value (no comment)
cut -d' ' -f1,2 ~/.ssh/fgt_admin_ed25519.pub
Verification: you should see two files, fgt_admin_ed25519 (private, mode 600) and fgt_admin_ed25519.pub. The cut output is a single line that starts with ssh-ed25519 AAAAC3NzaC1lZDI1NTE5.
Tip: Using PuTTYgen? Its saved public key is the multi-line SSH2 format. Copy the one-line key from the PuTTYgen window instead, or convert the file with ssh-keygen -i -f putty.pub.
Step 2: Create a least-privilege admin and attach the key
Goal: Bind the public key to an account that can only do what it needs, from where it needs.
Action: Create an access profile, then the admin with trusted hosts, the key, and a long random backup password.
config system accprofile
edit "ssh_netops"
set sysgrp read
set netgrp read-write
set fwgrp read-write
set loggrp read
next
end
config system admin
edit "netops-manny"
set accprofile "ssh_netops"
set vdom "root"
set trusthost1 10.0.10.0 255.255.255.0
set ssh-public-key1 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI<key-value>"
set password <long-random-string>
next
end
Generate the backup password with something like openssl rand -base64 32 and store it in your vault. It exists so the account cannot be used on the GUI without a password, not for daily use.
GUI verification: go to System > Administrators and open netops-manny. The profile and Restrict login to trusted hosts entries are visible there. The public key fields are CLI only, so confirm them with show system admin netops-manny.
Step 3: Pin the key and the host key on the client
Goal: Make the client offer only the right key and refuse a surprise host key.
Action: Add a host block to ~/.ssh/config. IdentitiesOnly yes stops your agent from offering every key it holds, which otherwise logs a failed attempt per wrong key.
Host fgt-lab
HostName 10.0.1.1
User netops-manny
IdentityFile ~/.ssh/fgt_admin_ed25519
IdentitiesOnly yes
HostKeyAlgorithms ssh-ed25519
StrictHostKeyChecking yes
On first contact, get the FortiGate host key fingerprint over a path you trust, such as from a host on the management segment, and add it to known_hosts before you connect:
ssh-keyscan -t ed25519 10.0.1.1 > /tmp/fgt.key
ssh-keygen -lf /tmp/fgt.key # compare with your deployment record
cat /tmp/fgt.key >> ~/.ssh/known_hosts
Step 4: Log in and watch the checks happen
Goal: Confirm the login succeeds by public key, from both ends.
Action: Turn on the SSH daemon debug on the FortiGate (console or another session), then connect verbosely from the workstation.
diagnose debug application sshd -1
diagnose debug enable
# ...connect from the workstation, then:
diagnose debug disable
diagnose debug reset
ssh -v fgt-lab 2>&1 | grep -E "can continue|Offering|accepts|Authenticated"
Expected success output (fingerprints shortened):
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: /home/manny/.ssh/fgt_admin_ed25519 ED25519 SHA256:q3x...
debug1: Server accepts key: /home/manny/.ssh/fgt_admin_ed25519 ED25519 SHA256:q3x...
Authenticated to 10.0.1.1 ([10.0.1.1]:22) using "publickey".
Note the first line. password is still on offer. Until Step 5, anyone who can reach the port from a trusted host can still guess passwords.
Step 5: Lock it down
Goal: Remove the password path, tighten the timers, and limit the crypto.
Action: Only after Step 4 works for every admin who uses SSH. admin-ssh-password disable applies to all admin accounts. Console access is not affected.
config system global
set admin-ssh-password disable
set admin-ssh-grace-time 30
set admin-lockout-threshold 3
set admin-lockout-duration 900
set strong-crypto enable
end
config system ssh-config
set ssh-kex-algo curve25519-sha256@libssh.org
append ssh-kex-algo diffie-hellman-group16-sha512
set ssh-enc-algo chacha20-poly1305@openssh.com
append ssh-enc-algo aes256-gcm@openssh.com
set ssh-mac-algo hmac-sha2-256-etm@openssh.com
append ssh-mac-algo hmac-sha2-512-etm@openssh.com
set ssh-hsk-algo ssh-ed25519
end
On builds before 7.4.4, the algorithm settings sit under config system global instead of config system ssh-config, and the host key setting is named ssh-hostkey-algo.
GUI verification: System > Settings shows the lockout and timeout values under Administration Settings. The SSH password and algorithm settings are CLI only.
Step 6 (optional): Use an X.509 certificate instead of a raw .pub key
Goal: Bind the admin to a certificate’s key pair, for shops that manage admin credentials through a PKI.
Action: Create or issue a certificate, import it as a remote certificate (public part only), and reference it with ssh-certificate.
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 \
-nodes -keyout fgt-admin.key -out fgt-admin.pem \
-days 365 -subj "/CN=netops-manny"
execute vpn certificate remote import tftp fgt-admin.pem 10.0.10.25
config system admin
edit "netops-manny"
set ssh-certificate "REMOTE_Cert_1"
next
end
ssh -i fgt-admin.key netops-manny@10.0.1.1
The GUI path for the import is System > Certificates > Create/Import > Remote Certificate (enable Certificates in System > Feature Visibility first). Need to change formats first? See Converting Certificates using OpenSSL.
Warning: What the FortiGate checks here is the key pair inside the certificate. Fortinet’s admin guide does not describe SSH login enforcing the certificate’s expiry date, chain, or revocation, so do not count on the 365-day validity to retire access. Test it in your lab before you build process around it, and remove the reference when someone leaves.
Tip: Certificates for the GUI are a separate mechanism: HTTPS admin login with a client certificate uses set peer-auth enable and a PKI peer-group on the admin account. That deserves its own post.
Verification and Validation
Run these after Step 5. Each one proves a different gate.
| Test | Command | Expected result |
|---|---|---|
| Only keys offered | ssh -v fgt-lab 2>&1 | grep "can continue" |
Authentications that can continue: publickey |
| Password path closed | ssh -o PubkeyAuthentication=no netops-manny@10.0.1.1 |
Permission denied (publickey). |
| Host key pinned | ssh -G fgt-lab | grep hostkeyalgorithms |
hostkeyalgorithms ssh-ed25519 |
| Trusted host enforced | Connect from an address outside 10.0.10.0/24 | Connection dropped, no prompt |
| Key login logged | execute log filter category 1 then execute log display |
Admin login successful, method ssh |
$ ssh -o PubkeyAuthentication=no netops-manny@10.0.1.1
netops-manny@10.0.1.1: Permission denied (publickey).
Troubleshooting and Gotchas
1. ssh_key_invalid logged on every good login
Symptom: the login works, but the event log shows “Administrator netops-manny login failed from ssh because of invalid ssh key” right before it, and a strict lockout threshold starts biting.
Cause: your agent offered other keys first. Each wrong key is a rejected attempt, and FortiGate logs it with reason ssh_key_invalid.
# More than one Offering line means the agent is spraying keys
ssh -v fgt-lab 2>&1 | grep Offering
ssh-add -l # what the agent holds
Fix: IdentitiesOnly yes plus an explicit IdentityFile, as in Step 3. For automation tools such as FortiNAC, turn off password fallback in the tool once the key works.
2. FortiGate still asks for a password
Cause: the key never matched. Usual suspects: the key was pasted with line breaks or in SSH2 multi-line format, the key type label does not match the key, or you edited a different admin account than the one in your User line.
show system admin netops-manny
diagnose debug application sshd -1
diagnose debug enable
Fix: set the key again as one line in the form "ssh-ed25519 AAAA...", and convert PuTTY files with ssh-keygen -i -f putty.pub first.
3. “REMOTE HOST IDENTIFICATION HAS CHANGED” after an upgrade
Cause: from 7.0.13 and 7.2.6 the FortiGate stopped offering an RSA host key and presents Ed25519 instead, and setting ssh-hsk-algo does the same thing. Your client remembered the old key. This is the warning you want to see when nothing changed, so verify before you clear it.
# Compare with your deployment record, then remove the stale entry
ssh-keyscan -t ed25519 10.0.1.1 | ssh-keygen -lf -
ssh-keygen -R 10.0.1.1
4. Locked out after admin-ssh-password disable
Fix: the serial console is not affected. Log in there and run config system global, set admin-ssh-password enable, end, then fix the key and lock it down again.
Sources
- Fortinet Admin Guide 7.6.6: Public key SSH access
- Fortinet Admin Guide 7.4.0: Administrative access using certificates
- Fortinet New Features 7.0.2: ECDSA in SSH administrative access
- Fortinet CLI Reference 6.2.1: config system admin (ssh-public-key1 to 3, ssh-certificate)
- Fortinet CLI Reference 7.6.0: config system ssh-config
- Fortinet Admin Guide 7.4.7: FortiGate encryption algorithm cipher suites
- Fortinet Admin Guide 7.2.13: Remote certificate
- Fortinet Community: How to limit the authentication mechanism that SSH uses (admin-ssh-password)
- Fortinet Community: Admin login failed because of invalid SSH key
- Fortinet Community: SSH key fails login to FortiGate (FortiNAC)
- Fortinet Community: Public key SSH authentication from FortiNAC to FortiGate (password requirement)
- Fortinet Community: How SSH server host key algorithms can be changed
- Fortinet Community: ssh-rsa host key no longer offered after 7.0.13 and 7.2.6
- Fortinet Community: System administrator best practices (trusted hosts, SSH grace time)
- Fortinet Community: System administrator best practices for FortiGate and FortiProxy
- Fortinet Community: How to prevent brute force attempts to a FortiGate administrator login
- CIS FortiGate 7.0.x Benchmark item 2.2.2: administrator lockout
No fluff. Just the config that works.