大网数据广告活动
服务器运维问答

Change default directory when I SSH to server

· 52CE 我爱测

I was wondering if there is a way to change the default directory that I get put into after I SSH into my Ubuntu server. 99% of the time when I'm logging into my server, it is to access files within a specific directory: /var/www…

问题原文

原帖链接 · Bob Flemming · CC BY-SA 3.0

I was wondering if there is a way to change the default directory that I get put into after I SSH into my Ubuntu server.

99% of the time when I'm logging into my server, it is to access files within a specific directory:

/var/www/websites

Is there a config file that I can edit that will make sure I am put straight into this directory when I login?

社区高分解答

原帖链接 · igorsantos07 · CC BY-SA 4.0

Since OpenSSH 7.6, you can use the new RemoteCommand option to achieve that.

In your ~/.ssh/config:

Host websites-my-host
    HostName <realhostname>
    IdentityFile ~/.ssh/keyfile
    User webmaster
    RequestTTY force # check if this is necessary
    RemoteCommand cd /var/www/websites && bash -l

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-04-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。