~/.ssh/rc Commands in this file are executed by ssh when the user logs in, just before the user's shell (or command) is started. See the sshd(8) manual page for more information.
很好,你找到了这一段,那么你已经完全明白接下来要干什么了。
~/.ssh/rc
1 2 3
#!/bin/sh
fastfetch
哦当然,记得检查一下 /etc/ssh/sshd_config,确保里面没有什么 PermitUserRC no 的设置…
这样就 OK 了!
这样就 OK 了…吗?
实际上是 OK 的,你也可以这么一直用下去,不会有什么问题。直到某一天,由于某些原因你突然需要 rsync 到你的服务器…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ rsync some_file.zip zfs: Host key fingerprint is SHA256:UGFknAum2hVeX+R/GxXWvbA2OKye8UJw2Q/6kihrgTY +--[ED25519 256]--+ | o*o .. oo| | +++ .... +| | +.+ o+.o o o| | . oo.o.* = ..| | o.. S o = o..| | .E.. = . .o| | . . . + * . | | o . * o | | ..o o | +----[SHA256]-----+ protocol version mismatch -- is your shell clean? (see the rsync manpage for an explanation) rsync error: protocol incompatibility (code 2) at compat.c(626) [sender=3.3.0]
rsync 爆掉了。(或者如果你想要通过 ssh 进行 git clone,同样会炸掉。)
何意啊。在你百思不得其解之际突然想到,是不是你的 fastfetch 搞的鬼?试试从 ~/.ssh/rc 中注释掉那一行,发现还真是。这要怎么办?总不能在服务器上单独开一个 rsync server 吧?
LOGIN PROCESS When a user successfully logs in, sshd does the following:
1. If the login is on a tty, and no command has been speci‐ fied, prints last login time and /etc/motd (unless pre‐ vented in the configuration file or by ~/.hushlogin; see the “FILES” section).
2. If the login is on a tty, records login time.
3. Checks /etc/nologin; if it exists, prints contents and quits (unless root).
4. Changes to run with normal user privileges.
5. Sets up basic environment.
6. Reads the file ~/.ssh/environment, if it exists, and users are allowed to change their environment. See the PermitUserEnvironment option in sshd_config(5).
7. Changes to user's home directory.
8. If ~/.ssh/rc exists and the sshd_config(5) PermitUserRC option is set, runs it; else if /etc/ssh/sshrc exists, runs it; otherwise runs xauth(1). The “rc” files are given the X11 authentication protocol and cookie in standard input. See “SSHRC”, below.
9. Runs user's shell or command. All commands are run un‐ der the user's login shell as specified in the system password database.
ENVIRONMENT ssh will normally set the following environment variables:
...
SSH_TTY This is set to the name of the tty (path to the device) associated with the current shell or command. If the current session has no tty, this variable is not set.