diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py
index <HASH>..<HASH> 100644
--- a/salt/modules/cmdmod.py
+++ b/salt/modules/cmdmod.py
@@ -433,6 +433,20 @@ def _run(
         if isinstance(cmd, (list, tuple)):
             cmd = " ".join(map(_cmd_quote, cmd))
 
+        # Ensure directory is correct before running command
+        cmd = "cd -- {dir} && {{ {cmd}; }}".format(dir=_cmd_quote(cwd), cmd=cmd)
+
+        # Ensure environment is correct for a newly logged-in user by running
+        # the command under bash as a login shell
+        try:
+            user_shell = __salt__["user.info"](runas)["shell"]
+            if re.search("bash$", user_shell):
+                cmd = "{shell} -l -c {cmd}".format(
+                    shell=user_shell, cmd=_cmd_quote(cmd)
+                )
+        except KeyError:
+            pass
+
         # Ensure the login is simulated correctly (note: su runs sh, not bash,
         # which causes the environment to be initialised incorrectly, which is
         # fixed by the previous line of code)
Adding needed code to ensure cmd tests are passing.