11

I have at this time two remote machines to which I am connecting. For one I am using private key with passphrase, and another one I am using root password.

Now, when I want to connect to machine with root password authentication, first ssh asks me for passphrase for machine which private key is inside my ~/.ssh directory,and then when I enter correct passphrase let me enter password for machine to which I am connectign with root password.

Is there any way to save sessions, and connection options, for example like in Putty?

Alan Kis
  • 237
  • You may also find a secure passwordless login convenient: https://askubuntu.com/questions/46930/how-can-i-set-up-password-less-ssh-login – Takkat Jan 31 '16 at 15:43

2 Answers2

25

You can use a per-user ssh-config file located in

~/.ssh/config

or a system-global one in

/etc/ssh/ssh_config

that stores the basic settings for each connection.

Example:

Host example_host
    User foo
    HostName example.com
    IdentityFile ~/.ssh/foo.key
    Port 23421

Having this in place, calling

ssh example_host

will open up a ssh-connection to example.com on port 23421, using the user foo and foo.key for authentication.

For an in-deep explanation, see the man page of ssh:

man ssh

Don't forget to set proper permissions on the config file:

chmod 600 ~/.ssh/config
hecke
  • 426
2

There is ~/.ssh/config as pointed out in the manual pages for ssh. It is well described there and in man ssh_config and also many times answered on askubuntu.

TL;DR:

# to preserve connections:
ControlMaster auto
ControlPath ~/.ssh/controlmasters/%r@%h:%p
ControlPersist 20m

# to provide correct keys, users, IPs and use aliases
Host yourHost
  Hostname IPaddress
  User user1
  IdentityFile ~/.ssh/id_ecdsa

Host yourSecondHost
  Hostname IP2
  User user2
  IdentityFile ~/.ssh/id_rsa

If you don't want to write passphrases, there is ssh-agent, where you can add the keys for your session:

eval `ssh-agent`
ssh-add ~/.ssh/id_ecdsa
# insert passphrase once
ssh yourHost
# will ask only for password
# next ssh connections will not ask for 
Jakuje
  • 6,605
  • 7
  • 30
  • 37
  • 1
    This is not a full answer, telling the OP to look somewhere in a manual themselves is worth being a comment at most. Furthermore, if you know any other duplicate questions about this here on Ask Ubuntu, please vote to close this question as duplicate of an already answered one. If you don't have the vote-to-close privilege yet, you can still flag the question as duplicate. – Byte Commander Jan 31 '16 at 13:21