As a web developer working with Ubuntu servers, I constantly find myself typing cd /var/www/websites immediately after SSH login. This repetitive task becomes annoying when you do it dozens of times daily. The default home directory might be fine for general users, but for those of us managing web projects, we need something more efficient.
The simplest approach is to modify your user's .bashrc file. This shell configuration file executes commands whenever you start a new shell session (like when you SSH into the server).
# Open the .bashrc file in your favorite editor
nano ~/.bashrc
# Add this line at the bottom of the file
cd /var/www/websites
# Save the file and reload your shell
source ~/.bashrc
For a more maintainable solution (especially when working with multiple servers), consider using SSH configuration:
# ~/.ssh/config
Host webserver
HostName your.server.ip
User yourusername
RequestTTY yes
RemoteCommand cd /var/www/websites && exec \$SHELL -l
Now you can simply type ssh webserver to connect and land directly in your web directory.
If you're administering a server where all developers should start in the web directory, modify the system-wide bash configuration:
# /etc/bash.bashrc
if [ -d "/var/www/websites" ]; then
cd /var/www/websites
fi
When changing default directories:
- Ensure the target directory has proper permissions (755 for directories, 644 for files)
- Consider using groups for web directory access control
- Never use root as your default login user
When working with web servers, most developers need immediate access to their web root directory (/var/www/websites in this case) rather than the default home directory. Constantly typing cd /var/www/websites after every SSH login becomes tedious.
The simplest approach is to edit the user's .bashrc file:
# Open the file
nano ~/.bashrc
# Add this line at the end
cd /var/www/websites
# Apply changes
source ~/.bashrc
For system-wide changes affecting all users:
sudo nano /etc/profile
# Add this before any existing code
if [ "$PWD" = "$HOME" ]; then
cd /var/www/websites
fi
For more advanced control, modify SSH config:
nano ~/.ssh/config
# Add host-specific configuration
Host myserver
HostName server.example.com
User myusername
RequestTTY yes
RemoteCommand cd /var/www/websites && exec \$SHELL
Remember these important notes:
- Never make web directories (
/var/www) as home directories - The
www-datauser should never have shell access - For production environments, consider using solution #3 for better security isolation
For quick access without changing configurations:
ln -s /var/www/websites ~/websites