With all that there is in terms of malware and keyloggers, you are never safe from anything. Even on macOS…
For example, an app could perfectly capture anything you enter into your macOS terminal. Fortunately, Apple has thought of everything and offers additional security on its terminal: Secure keyboard input.
This prevents applications on your computer or accessing your computer remotely from detecting and recording what you type in Terminal. It’s probably a great idea to enable it if you often enter passwords into your terminal, if you’re on a computer that’s not your own, or if you use a command-line password manager. .
To activate it, launch the terminal and in the menu, click on “Secure keyboard input”.