How to use `login` command to take a screenshot of another user's desktop?
The desktop is managed by the WindowServer daemon.

The communication with WindowServer is guarded so that only root and the current console user can access WindowServer.

Because you're using sudo, you have root privileges to be able to communicate with WindowServer.

In addition to this the current namespace is used to determine, which desktop is "your desktop". A session namespace is created for each currently logged in user.

When you use the login command, you're asked to enter your password. This is actually handled by the PAM subsystem. As part of the standard PAM setup on macOS, you're transferred to the correct (your own) session namespace, when logging on with the right password.

Therefore when you use "login" and enter a password, you get a screenshot of that user's desktop because you're in the right namespace.

However, when you use "login -f" you're bypassing PAM. Therefore the PAM modules are never executed, and you stay in the same name space you were before.

Therefore when using "login -f" to take the screenshot, you're actually getting a screenshot of the currently logged in user - and not the "abc" user you want.

You can read more about this in technical note TN2083:

https://developer.apple.com/library/content/technotes/tn2083/_index.html#//apple_ref/doc/uid/DTS10003794-CH1-SUBSECTION14