Ubuntu 16.04下.ssh/config有效字段及自定义配置问题咨询
Hey there! Let's tackle your SSH config questions step by step, since you're already up and running with basic entries on Ubuntu 16.04:
1. What are the valid fields in ~/.ssh/config?
There are dozens of valid configuration options, but here are the most useful ones (including the basics you're already using):
Host: The alias you use to initiate the connection (e.g.,Host my-serverlets you runssh my-serverinstead of the full command)HostName: The actual server hostname or IP addressPort: The SSH port number (defaults to 22 if omitted)User: The remote account usernameIdentityFile: Path to your private key file for public key authForwardAgent: Enables forwarding your local SSH agent to the remote server (yes/no)StrictHostKeyChecking: Controls how SSH handles unknown host keys (options:yes,ask,no)ServerAliveInterval: Sends periodic keep-alive packets to prevent idle connections from droppingCompression: Turns on session compression (yes/no)
For the complete list of every possible field, run man ssh_config in your terminal—it's the definitive reference for all available options.
2. Can I set a default landing directory (like user@my.server.com:/default/landing/path)?
There's no dedicated "default directory" field, but you can replicate this behavior perfectly using RemoteCommand and RequestTTY in your config entry. Here's a working example:
Host my-server HostName my.server.com User your-username Port 22 RemoteCommand cd /default/landing/path && exec $SHELL -l RequestTTY force
The exec $SHELL -l part is crucial—it ensures you get a full interactive login shell after changing directories, so your shell profiles (.bashrc, .profile, etc.) still load as expected. Without it, you'd end up in the right directory but without a proper interactive shell.
3. Can I disable PubkeyAuthentication in the config file and use password auth instead (I know scp can do this)?
Absolutely! You can force password authentication for a specific host by adding these two lines to your config entry:
Host my-server HostName my.server.com User your-username Port 22 PubkeyAuthentication no PasswordAuthentication yes
This tells SSH to skip public key auth entirely and go straight to prompting for your password. Just double-check that the remote server allows password authentication: on the server, look for PasswordAuthentication yes in /etc/ssh/sshd_config, and restart the sshd service (sudo systemctl restart ssh) if you needed to enable it.
内容的提问来源于stack exchange,提问作者marcman

