配置 SSH 登录后进入指定目录

发表信息: by Creative Commons Licence

需求

所有用户通过 SSH 登录到服务器时,默认进入到 /data 目录下。

解决

在 /etc/profile.d 目录下创建 cd_data.sh 文件,内容:

# cd /data when user login
cd /data

原理

/etc/profile.d 目录下的所有脚本,会在用户登录初始化环境时执行。1 2 3 4 5

扩展

  • /etc/profile: 系统初始化文件,登录 shell 时执行
  • ~/.bash_profile: 个人初始化文件,登录 shell 时执行
  • ~/.bashrc: 每次启动一个交互 shell 时都会执行

所以,全局的配置文件可以放到 /etc/profile 文件中。