首页 > 其他分享 >buildroot 添加ssh

buildroot 添加ssh

时间:2024-07-19 18:22:15浏览次数:9  
标签:buildroot sshd overlay no etc 添加 ssh yes

编译官方固件后发现没有ssh登录。修改buildroot添加ssh的功能。

  • 在buildroot目录下make menucofig

  • 添加OpenSSH包

    menuconfig界面中,导航到以下选项以启用OpenSSH:

    • Target packages --->
      • Networking applications --->
      • [*] openssh
        • [*] openssh-server
        • [*] openssh-client
  • 实测在添加选项编译后,可以启动ssh服务,但是并不能使用root账户登录,需要新建一个普通用户用普通用户登录才可以,需要修改/etc/ssh/sshd_config
    添加如下代码

    PermitRootLogin yes
    PasswordAuthentication yes
如果想讲这些配置模式在系统固件中配置。有以下两种方式
使用overlay方式
  • 1、在buildroot/board/<your_board>/overlay/etc/ssh/路径下创建sshd_config文件,并添加内容,编译固件的时候会将overlay的文件夹拷贝到生成的文件系统中去。例如上边的例子可以使用以下代码
mkdir -p board/<your_board>/overlay/etc/ssh
echo "PermitRootLogin yes" > board/<your_board>/overlay/etc/ssh/sshd_config
echo "PasswordAuthentication yes" >> board/<your_board>/overlay/etc/ssh/sshd_config

这里<your_board>是你的板子的名称。你可以选择任何合适的目录名。

  • 2、在Buildroot的menuconfig中配置Overlay文件系统,使其包含自定义的文件和目录。
    导航到以下选项并设置Overlay目录:

    • System configuration --->
      • (board/<your_board>/overlay) Root filesystem overlay directories

    将board/<your_board>/overlay添加到Root filesystem overlay directories中,以包含自定义的文件和配置。

使用BR2_ROOTFS_POST_BUILD_SCRIPT方式
  • 1、编写一个自定义脚本,在buildroot 编译过程中运行脚本来放置默认文件。首先,在buildroot中,例如我这里放在board/nuvoton/ma35d1/post-build.sh
  • 2、确保脚本有执行权限,chmod +x post-build.sh
  • 3、在buildroot 的menuconfig中配置脚本。
    • System configuration --->
      • (/path/to/post-build.sh) Custom scripts to run after building target (post-build.sh)
  • 4、在脚本中包含复制文件的操作,脚本的实例如下
#!/bin/sh

# 在镜像中添加文件或进行其他操作
# 例如,添加一个README文件
echo "这是一个默认的README文件" > ${TARGET_DIR}/root/README.txt

openssh默认配置

  • OpenSSH的默认配置文件通常位于/etc/ssh/sshd_config。以下是一个典型的默认配置文件的示例,包含一些常见的配置选项:
# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2

# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 2m
PermitRootLogin prohibit-password
StrictModes yes
MaxAuthTries 6
MaxSessions 10

# RSAAuthentication yes
# PubkeyAuthentication yes
# AuthorizedKeysFile	.ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# Allow TCP forwarding
AllowTcpForwarding yes
# Allow agent forwarding
AllowAgentForwarding yes
# Allow X11 forwarding
X11Forwarding yes
# Print the date and time when users log in
PrintMotd yes
# Print the banner file when users log in
#Banner none

# Allow client to request a pseudo-terminal
PermitTTY yes
# Log sftp level file transfers
Subsystem sftp /usr/lib/openssh/sftp-server

常见的配置选项说明

  • Protocol 2:指定使用SSH协议版本2。
  • HostKey:指定用于SSH协议版本2的主机密钥文件。
  • SyslogFacility:指定syslog的日志设施,默认是AUTH。
  • LogLevel:指定日志的详细程度,默认是INFO。
  • PermitRootLogin:控制root用户是否允许通过SSH登录。默认是- prohibit-password,表示禁止使用密码登录,可以使用yes、no、- without-password等值。
  • PasswordAuthentication:控制是否允许使用密码认证,默认是yes。
  • ChallengeResponseAuthentication:控制是否启用挑战响应认证,默认是no。
  • PermitEmptyPasswords:控制是否允许空密码登录,默认是no。
  • X11Forwarding:控制是否允许X11转发,默认是yes。
  • Subsystem sftp:指定sftp子系统的路径。

标签:buildroot,sshd,overlay,no,etc,添加,ssh,yes
From: https://www.cnblogs.com/lx--/p/18311632

相关文章

  • Prometheus-operator添加basic auth
    问题:Prometheus存在未授权访问,会导致/debug/pprof信息泄露漏洞解决方法:给prometheus添加basicauth由于operator部署的prometheus是通过crd控制的,不可以通过修改控制器的方式修改pod的配置,所以修改statefulset无法生效,需要通过修改prometheus对象添加basicauth权限。相关博客......
  • rsync数据同步服务,rsync+SSH同步,及inotify实时同步与rsync结合
    Linux系统下数据同步服务rsync一、rsync概述1.rsync的伙伴sync同步:刷新文件系统缓存,强制将修改过的数据写入磁盘,并且更新超级块async异步:将数据先放到缓冲区,在周期性(一般是30s)的去同步到磁盘rsync远程同步:==remodesynchronous==数据同步过程:sync数据同步=>保存⽂......
  • ASP.NET 应用程序添加 Swagger
    废话不多说,上教程。......
  • 2024-07-18 给vue项目添加自定义路由守卫
    要配置路由守卫要使用到vue-router,它是Vue.js官方的路由管理器,主要用于帮助开发者构建单页面应用(SinglePageApplication,简称SPA)。步骤一:新建路由文件,文件名随意,建议叫router.ts,规范一点//router.tsimport{createRouter,createWebHashHistory}from"vue-router";i......
  • 【efinix】 efinity Programmer里添加riscv的hex,Programner闪退
    问题在efinixefinityProgrammer里添加riscv的hex,Programner闪退分析1.某FAE提到可能hex文件有个小锁,应该是加密的问题变相解决方案使用【riscv-sapphire-ug-6.0.pdf77页】,CopyaUserBinarytoFlash(EfinityProgrammer)章节的方法,把FPGA程序和riscv的程序整合成一......
  • 深入探讨:Node.js、Vue、SSH服务与SSH免密登录
    深入探讨:Node.js、Vue、SSH服务与SSH免密登录在这篇博客中,我们将深入探讨如何在项目中使用Node.js和Vue,并配置SSH服务以及实现SSH免密登录。我们会一步步地进行讲解,并提供代码示例,确保你能轻松上手。一、Node.js与Vue的结合1.1Node.js简介Node.js是一个基于ChromeV8......
  • Nodify学习 二:添加节点
    Nodify学习一:介绍与使用-可乐_加冰-博客园(cnblogs.com)Nodify学习二:添加节点-可乐_加冰-博客园(cnblogs.com)添加节点(nodes)通过上一篇我们已经创建好了编辑器实例现在我们为编辑器添加一个节点添加model和viewmodel并将它们绑定到视图publicclassNodeViewMod......
  • 云计算实训07——搭建ssh服务、创建用户并授权、在RealServer创建code账号、SSH认证原
    一、搭建ssh服务1.安装ssh服务yum-yinstallopensshyum-yinstallssh-serveryum-yinstallssh-client2.关闭防火墙和selinux#关闭防⽕墙(临时)systemctlstopfirewalld#关闭开机⾃启动systemctldisablefirewalld#关闭selinux(临时)sete......
  • SSH、VNC在CentOS系统上的详细安装指南
    1.SSH(SecureShell)SSH是一种安全的远程登录协议,广泛用于Linux系统。安装和配置过程安装SSH服务器在CentOS系统上,使用以下命令安装OpenSSH服务器:sudoyuminstall-yopenssh-server启动并启用SSH服务sudosystemctlstartsshdsudosystemctlenablesshd......
  • Netcode for Entities如何添加自定义序列化,让GhostField支持任意类型?以int3为例(1.2.3
    一句话省流:很麻烦也很抽象,能用内置支持的类型就尽量用。首先看文档。官方文档里一开头就列出了所有内置的支持的类型:GhostTypeTemplates其中Entity类型需要特别注意一下:在同步这个类型的时候,如果是刚刚Instantiate的Ghost(也就是GhostId尚未生效,上一篇文章里说过这个问题),那么客......