LinuxBabe Community

How to edit .bash_profile or .profile file. and Append the following text into it so these two commands will be executed every time the user login

In the following article " https://www.linuxbabe.com/linux-server/setup-passwordless-ssh-login " it says to edit .bash_profile or .profile file. Append the following text into it so these two commands will be executed every time the user login.

But I haven’t understood this line –

Then edit .bash_profile or .profile file. Append the following text into it so these two commands will be executed every time the user login.

/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOSTNAME-sh

When I visited my root directory I can see this ” https://www.awesomescreenshot.com/image/6214942?key=904085093104a848f13d99265a7a6e3e

inside root directory in the file ” .profile ” this code is like this –

# ~/.profile: executed by Bourne-compatible login shells.

if [ “$BASH” ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n 2> /dev/null || true

So where to add the code can you please give me the modified file ??

Thanks

Append means “add to the end of something”. So you should add the following two lines at the bottom of the .profile file, each on its own line.

/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOSTNAME-sh

So .profile file will look like this -

# ~/.profile: executed by Bourne-compatible login shells.

if [ “$BASH” ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n 2> /dev/null || true

/usr/bin/keychain $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOSTNAME-sh

Am I right?

Yes. It’s correct.