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

How to Stop SSH From Timing Out

Add these lines:

ClientAliveInterval 60
ClientAliveCountMax 3

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

When building a multilingual React application, translating the visible content is just part of the job. To make your app SEO-friendly and user-centric, you also need to:

  • Translate URLs/slugs (e.g., /about-us/fr/a-propos)
  • Maintain SEO with hreflang for each language
  • Improve UX by aligning URLs with user language
  • Ensure route accessibility via browser language or manual switching

May 04, 2025
Read More
Tutorial

Globalization in React (2025 Trends & Best Practices)

const formatCurrency = (value, lng) => {
  const currency = lng === 'ar' ? 'EGP' : 'USD';
  return new Intl.NumberFormat(lng, {
    style: 'currency',
    currency
  }).format(value);
};

Languages like Arabic and Hebrew need RTL layouts. Use CSS:

May 04, 2025
Read More
Tutorial

Implementing Internationalization (i18n) in a Large React Application (2025 Guide)

  • Add lang attribute dynamically to <html lang="...">
  • Use language subpaths (e.g., /en/home, /fr/home) for SEO indexing
  • Translate all visible UI, not just text
  • Localize URLs and metadata (title, description)
  • Use hreflang tags in SSR setups (Next.js, Remix)

Use localStorage via i18next-browser-languagedetector:

May 04, 2025
Read More

Discussion 0

Please sign in to join the discussion.

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