I can parse the /etc/passwd with augtool: myuser=bobusershome=`augtool -L -A --transform Passwd incl /etc/passwd print /files/etc/passwd/$myuser/home | sed -En 's/\/.* = (.*)/\1/p'`...but it seems a little too convoluted.Is there any simple, dedicated tool for displaying users'home (like usermod can be used to change it)?
What is the reliable way of getting each user's .ssh directory from bash?
bash;command line;scripting;hosts
You should never parse /etc/passwd directly. You might be on a system with remote users, in which case they won't be in /etc/passwd. The /etc/passwd file might be somewhere else. Etc.If you need direct access to the user database, use getent.$ getent passwd phemmerphemmer:*:1000:4:phemmer:/home/phemmer:/bin/zsh$ getent passwd phemmer | awk -F: '{ print $6 }'/home/phemmerHowever there is also another way that doesn't involve parsing:$ user=phemmer$ eval echo ~$user/home/phemmerThe ~ operator in the shell expands to the specified user's home directory. However we have to use the eval because expansion of the variable $user happens after expansion of ~. So by using the eval and double quotes, you're effectively expanding $user first, then calling eval echo ~phemmer.Once you have the home directory, simple tack /.ssh on to the end.$ sshdir=$(eval echo ~$user/.ssh)$ echo $sshdir/home/phemmer/.ssh