Score:1

Pass password in ssh config

mp flag

Is there any way to pass a password using .ssh/config? I'm trying to set up a way to login to a server under a specific user and then switch automatically to root when I connect (need to input password).

For now, I have:

Host server
 HostName hostname.server.com
 User not-root
 Port 1234
 RemoteCommand su
  • I have to use these steps (user -> su)
  • I have to use this key (with passphrase)

Thanks!

in flag
use sudo instead.
mp flag
I still need to input the user password
in flag
No, you can configure sudo to allow the switch without password.
in flag
Does this answer your question? [How to sudo another user without password](https://serverfault.com/questions/835557/how-to-sudo-another-user-without-password)
mp flag
I can't actually change anything on the server so that's not an option for me
nagu avatar
br flag
you could try to use "expect" to automate the ssh followed by "su" if it is available for your platform. check out https://stackoverflow.com/questions/22147566/expect-script-for-remote-ssh-login-and-executing-commands
cn flag
Bob
Uhhh: *"I can't actually change anything on the server so that's not an option for me"* - but you have the root password, right?
Score:1
cn flag
Bob

In general most sysadmins would configure things so that their automation does not rely on passwords.

SSH

For SSH authentication the easiest is to create a key-pair where the private key is not password protected.

If you need a passphrase on the private SSH key, adding that key / passphrase to ssh-agent (or a Mac OSX keychain) is a one-off action after which so you won't need to be prompted for the passphrase anymore.

If that is not an option, use sshpass in your scripts/commands use a password/passphrase from the command line

On the server

Again the easiest/conventional solution is to prevent having to enter a password.

Your options for that depend on the level of control you have

  • set up a NOPASSWD sudo policy (ideally only for the relevant command(s)) which will allow you to execute sudo some-command --with args or sudo -i for an interactive login session without entering a passphrase.

  • set up the root account for direct remote ssh logins (not the best solution, but when you don't allow password auth, only key based auth...)

  • depending on the set-up simply add your account to a "sudo" , "wheel" or "admin" group and you get full admin rights

When you really want to submit a password, expect is the utility for automating that

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.