If you have logged into your Adsense recently you would've seen the warning of earnings at risk. If you click on "fix now" you'll get to see a page where you can download your ads.txt file.
If you're running a blog or website on private hosting by simply going in the file explorer of your host and upload the file in the root directory.
In the case of Blogger/Blogspot,
- Log into your Blogger account and select the blog you want to set up ads.txt file for.
- In the left-hand side menu, you'll find Settings.
- Go to Search Preferences and under monetization enable Custom ads.txt
- Open your ads.txt you downloaded from Adsense.com and copy the content from this file.
- Paste the content the editor you get after enabling custom ads.txt
- See images below in case of any doubt.