Silence ssh-add

sshssh-agent

I have a cronjob that runs some tasks, and at the beginning of the script it runs is an ssh-add call ( it doesn't run as the user with the appropriate key so it needs adding, and in future it may well use a deploy key defined in version control ). This looks something like this:

ssh-agent bash -c "ssh-add /home/tomjn/.ssh/id_rsa; etc... "

I want to silence it, as this cronjob runs regularly, and I have a lot of emails in my inbox that are completely useless to me stating that yes, the key was added. I only want emails when things go wrong, like a git pull remote connection hang up etc, which does happen.

So TLDR, I keep seeing this:

Identity added: /home/tomjn/.ssh/id_rsa (/home/tomjn/.ssh/id_rsa)

How do I shut it up?

I've tried things like:

ssh-add /home/tomjn/.ssh/id_rsa > /dev/null

But to no avail. The man page doesn't indicate that there's a --quiet parameter, is there something else I can do to silence the output?

Best Answer

The output of the ssh-add command is on STDERR. You need to redirect STDERR to /dev/null to suppress the output:

mtak@frisbee:~$ ssh-add .ssh/id_rsa 2>/dev/null
mtak@frisbee:~$ 

or alternatively suppress all output by ending the command with >/dev/null 2>&1

Related Question