As I'm sure you know, troubleshooting is a process of elimination and often requires a fair bit of patience. I'd like to try a few things to try and get to the bottom of this for you.
1. Confirm it hangs during login
If the process it's hanging at is really during login, this implies that the process is still waiting to create a login session. Assuming this is the case, then it wouldn't have tried to start the shell yet.
To confirm this, the next time you experience this issue launch Activity Monitor to check if the shell is running or whether you only see a login process.
Once you've had a chance to do this, report back with what you found.
NOTE:- If you happen to have other terminals open, make sure you're checking the corresponding process. My guess is that the hanging process is the one with the highest Process ID (PID) number.
2. What is the Terminal title?
The next time you have this issue can you take a note of what the title of the Terminal window is and report back?
3. Kill sudo
You state that rebooting your MBP always resolves this issue.
However, the next time you have this issue (maybe after doing what I described at 1 above), I'd like you to try killing sudo from Activity Monitor.
Once you've tried this, let us know what happens.
4. Try moving your .bash* files
It is possible (for various reasons) you may have a .bash_profile file in your user directory and this is causing intermittent problems. This is something you may not even be aware of, but you can use Automator to run a script that finds and moves any .bash files.
Here is an example script for doing this:
cd ~
mkdir moved
for F in .bash*
do
mv $F moved
done
This script moves all files starting with .bash in your home folder to a newly created moved subfolder.
After running the script, check this folder and let us know if in fact you have any files in it.
NOTE:- You can label the new subfolder anything you want. To do so, just change the two occurrences of moved in the script to whatever label you'd like to use.
[UPDATE]
Some more things to try.
5. Try clearing the *.asl files
If you haven't already, try clearing out the *.asl files. To do this use the following:
sudo rm -rf /private/var/log/asl/*.asl
NOTE:- This may take some time as it creates a new shell. When complete, make sure you fully quit the Terminal for the changes to take affect.
6. Safe Mode
Do you notice any difference in behaviour when you start your MBP in Safe Mode? To boot into Safe Mode:
- Fully shut down your Mac
- Restart your Mac
- Immediately press the Shift key and keep it down
- Let go of the Shift key when you see the login window (NOTE: If you have FileVault enabled you may need to log in twice).
- Once your MBP starts up try using Terminal and see if you can still replicate the issue?
- When finished, you can exit Safe Mode by restarting your MBP as normal
7. Open Directory
This probably doesn't apply in your case since you don't mention it, but if you're connected to an Open Directory network this could also be causing you problems. Usually this would only entail waiting for about 10 - 15 seconds, but I have seen reports of terminal logins taking five or more minutes to complete in this situation.
Best Answer
If I understand correctly, you want to connect to your High Sierra machine from an external source via something like netcat (nc), send commands to bash, and view the response.
There are more secure and simpler ways to do this using ssh, but presuming this is some kind of experiment or development trick, here's how you can do what you're asking.
My answer is based on an answer I found elsewhere on SE (https://superuser.com/a/607855), which itself is based on other SO/SE answers.
First make a fifo:
Then start 'nc' using the fifo as its input, piping its output to bash, and redirecting bash's output to the fifo:
(The '-i' flag for bash indicates an interactive shell, and may not be desirable for this use case.)
From the remote device (in my testing, myself):
If you want to reverse the roles, i.e. the High Sierra machine is establishing the connection to the remote device, and giving the remote device access to bash on the HS host, you would move the listen flag (-l). So, the remote device would start netcat first in listen mode:
Then the High Sierra host would connect to the remote device: