Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear terminal after SSH login?

Tags:

bash

terminal

ssh

I am trying to connect to a server via ssh. Once connected, terminal should be cleared.

Due to generated keys, I can connect to the server via ssh usr@svr without being prompted a password. This works.

In order to get rid off

The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

I would usually just type clear. However, I would prefer not to type this every time but automate the procedure instead.

ssh usr@svr "clear" --> "TERM environment variable not set.". I googled several solutions about unset environment variables, but without success.

So instead, I tried ssh -t usr@vr "clear"; this successfully clears the terminal, but also closes the connection right away ("Connection to IP closed."). Computer connects to server, clears the screen, closes the connection.

Next attempt was to create a bash script on the server to be run after connecting to it.

#/bin/bash
clear
## cl.sh, chmod +x

ssh usr@svr ./cl.sh --> "TERM environment variable not set.".

Another attempt was to create a bash script connecting to the server and clearing the terminal via ENDSSH.

#/bin/bash
ssh usr@svr <<'ENDSSH'
clear
ENDSSH
## sc.sh, chmod +x

Running this results in:

> ./sc.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
Linux raspberrypi 3.18.7-v7+ #755 SMP PREEMPT Thu Feb 12 17:20:48 GMT 2015 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
TERM environment variable not set.

I am a beginner at this, so please be patient if I have made a very obvious mistake. I tried to be as detailed as possible and researched this before posting, but could not find an answer to my question. For example, commands other than "clear" work (ssh usr@svr ls), but that does not help me.

like image 456
prankousky Avatar asked Oct 15 '25 08:10

prankousky


2 Answers

I have found another easy solution

ssh -t usr@svr 'clear;bash'
like image 52
prankousky Avatar answered Oct 19 '25 00:10

prankousky


The text your question refers to is part of the message-of-the-day (MOTD).

If you can become root on the server, you can just modify that message in /etc/motd. Note that depending on the server's distribution, this file will usually be generated somehow (overwriting any changes), e.g. on Debian it is generated from /etc/motd.tail at boot, so you might have to change that file instead.

See manpage motd(5).

like image 24
Michael Jaros Avatar answered Oct 18 '25 22:10

Michael Jaros



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!