15

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)
8
  • use sudo instead. Commented Dec 1, 2021 at 8:17
  • I still need to input the user password Commented Dec 1, 2021 at 8:29
  • No, you can configure sudo to allow the switch without password. Commented Dec 1, 2021 at 8:30
  • Does this answer your question? How to sudo another user without password Commented Dec 1, 2021 at 8:30
  • I can't actually change anything on the server so that's not an option for me Commented Dec 1, 2021 at 8:52

1 Answer 1

7

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.