Connect the USB flash drive directly to your Mac.
Open Terminal, which is located in the Utilities subfolder of the Applications folder.
Type or paste one of the following commands The installer must be located in the Applications folder. MyVolume is the name of the USB flash drive. If the name is different, rename it or replace MyVolume in the command as needed. When prompted, enter your administrator password. No characters are displayed in Terminal as you type. Then press Enter.
If prompted, type Y to confirm that you want to erase data from the media and press Enter. The terminal displays the progress of erasing the volume data. If Terminal fails to erase the data, use Disk Utility to erase the volume using the Mac OS Extended (Journaled) format, then start over.
After erasing the volume data, you will see a notification that Terminal wants to access the files on the removable volume. Click OK to continue copying.
When Terminal reports that installation media is available, the volume will have the same name as the installer, such as Install macOS Sonoma. Now you can exit the terminal and remove the media.