Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1234  / 3 Years ago, sun, may 16, 2021, 2:57:57

I have ubuntu server at home, and I use SSH keys to log in via terminal from my laptop. Rarely, but mostly from work, I need to access this server, but I dont want to copy keys on my work laptop - Id rather just use plain password for that.



So if I enable password log in from ssh config file, it will ask me password on my laptop too even though it contains keys, right?



Is there a way to stop this behavior?



Thanks.


More From » ssh

 Answers
5

It is possible to force your laptop to use the keyfile even if both the password and keybased approach are available. If you're currently connecting with ssh [email protected] -p 22, edit ~/.ssh/config and add:



Host your.host.tld
PreferredAuthentications publickey


This configuration file can be used to make you type even less:



Host home
Hostname your.host.tld
User user
PreferredAuthentications publickey
Port 22


With that configuration, you just need ssh home.



It's possible to restrict password-based logins to a certain IP address. In /etc/ssh/sshd_config, you'd have a line that disabled password-based auth: PasswordAuthentication no. To enable it for logins from a certain IP, you could use:



Match Address 12.34.56.78
PasswordAuthentication yes


I suggest you to use keybased auth even if on work. It's much safer than password-based auth as it cannot be bruteforced that easily. You can have multiple keys for the same account, that should not be an issue.



For more fancy configuration directives, see the manual page of ssh_config(5). (for the server side, see sshd_config(5))


[#39297] Sunday, May 16, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cupwire

Total Points: 365
Total Questions: 126
Total Answers: 125

Location: Malaysia
Member since Thu, Feb 16, 2023
1 Year ago
cupwire questions
;