DeveloperBreeze

How to Set a Default Directory When SSHing into Your VPS

Introduction

When you log into your VPS via SSH, you might want to start in a specific directory rather than your home directory. This is especially useful for developers and system administrators who frequently work in a particular project folder.

In this tutorial, we'll guide you through how to set a default directory when you SSH into your VPS.


Prerequisites

  • Access to your VPS via SSH
  • Basic knowledge of the command line
  • A text editor installed on your VPS (nano, vim, etc.)

Step-by-Step Guide

Step 1: SSH into Your VPS

ssh your-username@your-vps-ip

Replace your-username with your SSH username and your-vps-ip with your VPS IP address.


Step 2: Determine Your Shell

Check which shell you're using:

echo $SHELL
  • If the output includes /bash, you're using bash.
  • If it includes /zsh, you're using zsh.

Step 3: Edit the Shell Configuration File

Depending on your shell, you'll edit a different file:

ShellConfiguration File
bash~/.bashrc or ~/.bash_profile
zsh~/.zshrc

> Example below assumes you're using bash (.bashrc).

Open the .bashrc file:

nano ~/.bashrc

_or_

vim ~/.bashrc

Add the cd Command at the End of the File:

cd /home/examplewebsite/htdocs/examplewebsite.com

This command will change the directory automatically when you log in via SSH.


Save and Exit:

  • If using nano:

Press CTRL + OEnterCTRL + X.

  • If using vim:

Press ESC, then type :wqEnter.


Step 4: Apply the Changes

Apply the changes immediately without logging out:

source ~/.bashrc

_or just log out and back in._


Step 5: Verify the Configuration

Logout and reconnect via SSH:

exit
ssh your-username@your-vps-ip

You should now start in the /home/examplewebsite/htdocs/examplewebsite.com directory.


Troubleshooting

  • Permission Issues:

Make sure your SSH user has permission to access the specified directory.

  • Directory Existence:

Double-check that the directory exists.

  • Shell Type:

Ensure you're editing the correct configuration file for your shell (.bashrc, .zshrc, etc.).


Conclusion

By following these steps, you can set a default directory when SSHing into your VPS, streamlining your workflow and saving time navigating to your project folders. This simple tweak can greatly enhance your efficiency when working on your server.

Related Posts

More content you might like

Tutorial

ما هو حقن التبعيات (Dependency Injection)؟

تستخدم العديد من الأُطر الحديثة—مثل Laravel، Symfony، Spring، Angular—حاويات (Containers) تقوم بإدارة وإنشاء التبعيات تلقائياً. يسمح هذا للمطور بالتركيز على منطق العمل بدلاً من إدارة إنشاء الكائنات يدوياً.

على سبيل المثال، في Laravel يمكن تسجيل خدمات داخل الـ Container ليتم حقنها تلقائياً:

Dec 01, 2025
Read More
Article

أفضل طرق إزالة الصدأ من العدّة والمسامير – دليل شامل منزلي واحترافي

  • جفّف الأدوات جيدًا.
  • ضع طبقة خفيفة من زيت معدني، أو WD-40، أو زيت ماكينة الخياطة.
  • احفظ الأدوات في مكان جاف بعيد عن الرطوبة.

عند التعامل مع مئات المسامير، من غير المنطقي تنظيف كل مسمار على حدة. توفر تقنية التحليل الكهربائي حلولًا عملية تسمح بتنظيف 100–300 مسمار في دفعة واحدة.

Dec 01, 2025
Read More
Tutorial

How to Stop SSH From Timing Out

Restart SSH:

sudo systemctl restart sshd

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

import { useTranslation } from 'react-i18next';

export default function Home() {
  const { t } = useTranslation();
  return (
    <div>
      <h1>{t('title')}</h1>
    </div>
  );
}

Create pages/About.js:

May 04, 2025
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!