Should structured data for the search box and logo only be in the main page of website or should be in all of the pages? and why?
My goal is to use them to get rich snippets in Google.
Your structured data must be a true representation of the page content.
Put the structured data on the page that it describes, unless specified otherwise by the documentation.
Thus, you can easily set the markup for the search box and logo on all pages that have a search box and a logo in the main (visible to users) content.