Linux远程登录自定义提示信息
· 技术积累 · Linux SSH

一般来说默认远程登录的提示信息都是这样的:

Connecting to 192.168.16.191:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Fri Sep  7 00:13:18 2018 from 192.168.17.180
[root@localhost ~]# 

一,如果要自定义一些提示信息在登录后显示出来,我们应该修改/etc/motd这个文件:

[root@localhost ~]# ll /etc/motd 
-rw-r--r--. 1 root root 0 Jun  7  2013 /etc/motd
[root@localhost ~]# vim /etc/motd
#注意:文件中所有的文本和字符都不会被转义的,会直接打印出来的
#编辑motd文件添加下面一句话然后保存退出:

禁止非法登录!允许正常登录! 

我们重新打开一个连接就可以看到登陆后,会有刚加的自定义信息显示出来:

Connecting to 192.168.16.191:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Thu Sep 13 23:28:40 2018 from 192.168.17.180
禁止非法登录!欢迎正常登录!
[root@localhost ~]# 

Linux远程登录自定义提示信息


二,如果要自定义一些执行命令的结果显示,我们应该修改/etc/bashrc这个文件:

[root@localhost ~]# ll /etc/bashrc 
-rw-r--r--. 1 root root 2853 Nov  5  2016 /etc/bashrc

#编辑文件最下方添加我们要执行的命令即可
[root@localhost ~]# vim /etc/bashrc 


  # You might want to have e.g. tty in prompt (e.g. more virtual machines)
  # and console windows
  # If you want to do so, just add e.g.
  # if [ "$PS1" ]; then
  #   PS1="[\u@\h:\l \W]\\$ "
  # fi
  # to your custom modification shell script in /etc/profile.d/ directory
fi

if ! shopt -q login_shell ; then # We're not a login shell
    # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
        case ":${PATH}:" in
            *:"$1":*)
                ;;
            *)
                if [ "$2" = "after" ] ; then
                    PATH=$PATH:$1
                else
                    PATH=$1:$PATH
                fi
        esac
    }

    # By default, we want umask to get set. This sets it for non-login shell.
    # Current threshold for system reserved uid/gids is 200
    # You could check uidgid reservation validity in
    # /usr/share/doc/setup-*/uidgid file
    if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
       umask 002
    else
       umask 022
    fi

    SHELL=/bin/bash
    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . "$i"
            else
                . "$i" >/dev/null
            fi
        fi
    done

    unset i
    unset -f pathmunge
fi
# vim:ts=4:sw=4

#此处为我们自定义的命令
df -h

我们再重新打开一个连接可以看到登陆后,刚加的磁盘使用信息显示出来:

Connecting to 192.168.16.191:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Thu Sep 13 23:39:04 2018 from 192.168.17.180
#注释
禁止非法登录!欢迎正常登录!
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   14G  3.4G   11G  26% /
devtmpfs             1.9G     0  1.9G   0% /dev
tmpfs                1.9G     0  1.9G   0% /dev/shm
tmpfs                1.9G  191M  1.7G  11% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1           1014M  139M  876M  14% /boot
tmpfs                380M     0  380M   0% /run/user/0
[root@localhost ~]# 

Linux远程登录自定义提示信息


本文最后更新时间 2024-03-31
文章链接地址:
https://hope.jinchuang.org/archives/261.html
本站文章除注明[转载|引用],均为本站原创内容,转载前请注明出处
统计文本中每个字符出现的次数
Nali 离线ip数据库文件
苹果CMS v10内容管理系统搭建
bin/ld: Dwarf Error: found dwarf version '5', this reader only handles version 2, 3 and 4 information.

微信小程序

Dos cmd命令和Bash shell 命令之间的对比

我要留言