靳闯博客 记录是一种习惯,分享是一种态度
  • 波浪
  • 波浪
  • 波浪
  • 波浪
Linux远程登录自定义提示信息
发表于: | 分类: 技术积累 | 标签: Linux SSH | 评论:0 | 阅读: 294

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

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 ~]# 

ssh0.png


二,如果要自定义一些执行命令的结果显示,我们应该修改/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 ~]# 

ssh1.png


商业转载请联系作者获得授权,非商业转载请注明出处,谢谢合作。


如果这篇文章帮助到了你,我感到十分荣幸!

或许你不想写点什么·但我依旧在这里

icon_mrgreen.pngicon_neutral.pngicon_twisted.pngicon_arrow.pngicon_eek.pngicon_smile.pngicon_confused.pngicon_cool.pngicon_evil.pngicon_biggrin.pngicon_idea.pngicon_redface.pngicon_razz.pngicon_rolleyes.pngicon_wink.pngicon_cry.pngicon_surprised.pngicon_lol.pngicon_mad.pngicon_sad.pngicon_exclaim.pngicon_question.png2018new_aini_org.png2018new_baobao_thumb.png2018new_erha_org.png2018new_kuxiao_thumb.png2018new_yun_thumb.png2018new_hufen_thumb.png2018new_gui_org.png2018new_xiaoerbuyu_org.png2018new_heixian_thumb.png2018new_wabi_thumb.png2018new_tianping_thumb.png

站点地图 网站地图
豫ICP备17003270号 | Copyright © 2018 💖 靳闯博客
Typecho🍹Sgreen
TOP