I've got SSH passwordless set up, however it prints the MoTD when it logs in. Is there anyway to stop that happening from the client side?
I've tried ssh -q
but that doesn't work. I don't want to use ~/.hushlogin
nor do I want to change the server set up. The only thing that can work is to quiet all output, with >/dev/null 2>&1
. However, I don't want to ignore errors in case there actually is a problem. Even doing >/dev/null
doesn't work, since ssh
seems to print the motd to the stderr.
Update & reasoning I'm running backup in a cron. I don't want to get a cron email unless an error has occured. However if the motd is printed I'll get an email all the time.
I want to keep the motd being printed because that has legal implications. The motd says "unathorized access prohibited". You need to have this sort of statement in there to legally prevent people from access it (like a no trespassing sign). Hence I don't want to blanket disable it all the time.
I'm not sure why you have an aversion to doing this correctly - either on the server a la
and
Or adding ~/.hushlogin for each user.
Hint, for ~/.hushlogin, add it to /etc/skel so new user home directories are created with the file.
Update:
Without more information about your backup cron job, my only other suggestion is to redirect the output of the command to a file (or let cron capture it in email) and the output of the ssh session to /dev/null. Something like:
Or
I'd have to play around with the commands a bit, but that should get you started.
@note All examples assume you've set a variable
connectionString
with something likeconnectionString=user@server
.How I got to the solution
Using
ssh -T
should work for simple commands. For example this doesn't print any extra information:The problem is when you try to use here-doc to run many commands. For example - bellow will NOT work - it will echo message of the day (MoTD) and also might show you "stdin: is not a tty".
To workaround the issue you need first save commands to local variable and the send them to remote server.
But that's messy...
Final solution
Make a universal function (note that it can take a string or HEREDOC as commands).
Examples
Use this like so:
Or like so:
Or like so:
Or even like so:
If you want this on a per-user basis, just do a
touch ~/.hushlogin
and you're all set with OpenSSH.Update: As pointed out elsewhere,
pam_motd
may be configured to not use a per-user.hushlogin
; check/etc/login.defs
forHUSHLOGIN_FILE
. It may be configured to have all users listed in/etc/hushlogins
or similar.How about this hack? ;-P
The following is not valid:
Passing
-T
to ssh to disable tty allocation:What operating system is this? On some systems (like ubuntu) the motd isn't printed by the ssh server (PrintMotd in /etc/ssh/sshd_config), but by pam with pam_motd. If this is the case then you probably can't control it from the client.
You have to do it on the server:
On debian/ubtuntu also hash the line with pam_motd.so:
Don't execute ssh command directly by cron.
Make an helper bash script instead, executing the ssh job and fetching the output, the errors and the error code if needed; eventually parse them in order to remove unwanted strings from error messages (the MoTD in your case) and then re print on the bash script output and error streams what you have obtained in such a way.
Than put this bash script in cron and live happy :)
Note: This is a general solution, and has to work whatever is the job you have to perform via ssh. It is only client side too, which should fulfill your needs ... the only dependence of the client on the server config is the knowledge of the exact message you want to cut out from the std err or out of ssh client
Just a sidenote (would have been a comment, if I could post that): Contents of motd are shown after successfull login to the system. If I'd like to legally prevent people from accessing a box I'd rather do that by a "Banner" in sshd_config. The contents are displayed after entering Username but before authenticating.
Either you haven't tried what you're describing, or your servers are configured wrong!
Here's what I just tried on RHEL5:
I don't suppose you need the disclaimer to be sent to non-interactive shells, do you? (If anyone claims you do, do me a favor, kick them in the nuts.) Because that's exactly why there's a distinction between interactive shells and non-interactive ones.
But in any case, here's what I do because I don't like mail from cron: I pipe the output to logger. Just pipe it through tail to remove the first few (let's say 3) lines of your pointless disclaimer as such (untested code, I don't have access to my scripts):
If I understand you, you need motd for other reasons but don't need motd for backup. In the config of sshd cannot set it up by user basis only globally. Therefore you need solve motd supression in client side. But there is not difference between motd's text and the backup software's error messages. Both are text in the terminal. The only solution I see to make difference between this two message then filter the motd's one. Because software's messages are hard to modify I suggest to modify motd's text. For example put a frame around:
Then you should filter out the text between the frame and drop it.