Yuri Slobodyanyuk Blog on Information Security 2024年09月12日
Fortigate ssh access with public key authentication
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

介绍在Fortigate中为管理员用户启用SSH认证的方法,包括创建公私钥、导入公钥、使用生成的密钥连接以及可选的禁用密码认证以提高安全性。

🎯创建公私钥:在Linux命令行运行ssh-keygen命令,生成公钥和私钥,并设置相关信息,如保存位置和密码短语等。公钥和私钥分别保存于指定位置,生成的信息包含密钥指纹和随机艺术图像。

🔑导入公钥:将在Step1中生成的公钥id_rsa.pub导入到Fortigate中。通过配置系统管理员相关命令,将公钥设置到指定用户下。

💻使用生成的密钥连接:使用ssh命令并指定私钥文件的路径以及Fortigate的IP地址,进行SSH连接。

🛡️可选操作:为了更好的安全性,可禁用管理员用户的密码认证。但需先确保能使用公钥成功连接,然后通过相关配置命令进行设置。

Entering each time username and password isn’t fun when doing it daily to the same equipment. Saving password in some automated script (Paramiko, Expect, etc) is not very secure per se. Using the SSH private/public key pair, on the other hand, answers all the needs – easy, secure, time saving. Here is how to enable SSH authentication for an admin user in Fortigate:

Step1: Create public and private keys.
On linux command line we run: $ ssh-keygen

Generating public/private rsa key pair.Enter file in which to save the key (/home/myuser/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/myuser/.ssh/id_rsa.Your public key has been saved in /home/myuser/.ssh/id_rsa.pub.The key fingerprint is:be:1b:3c:e0:1e:7d:1e:29:04:27:1d:1d:11:41:33:54 myuser@myhostThe key's randomart image is:+--[ RSA 2048]----+ 

Step 2. Import PUBLIC key saved in Step 1 in the file id_rsa.pub to the Fortigate:

config system admin
(config)# edit myuser
(myuser)# set ssh-public-key1 "ssh-rsa AAAAB3Nza .. … … …. 0lTo9P myuser"

Step 3. Connect using the the generated keys:
ssh -i /home/myuser/.ssh/id_rsa ip-of-the-fortigate

Step 4 (Optional, but recommended). Disable password-based authentication for admin user altogether

You still can connect with a password, even if a public key authenticaiton is enabled. The one does not disable the other. But for better security you could disable password authentication for an admin user and leave only public key-based one. First, make sure you can connect with your public key just fine. Then:

# config sys global(global) # set admin-ssh-password disable(global) # end

That is it, of course it will work for other Fortinet products having SSH access like Fortimail, FortiAnalyzer, etc .

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Fortigate SSH认证 安全性 密钥连接
相关文章