Skip to main content
edited body
Source Link
xhienne
  • 18.3k
  • 2
  • 58
  • 71

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one in bash that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -Ii ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one in bash that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -I ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one in bash that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -i ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}
added 8 characters in body
Source Link
Eric Renouf
  • 18.7k
  • 7
  • 51
  • 66

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one in bash that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -I ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -I ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one in bash that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -I ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}
added 399 characters in body
Source Link
Eric Renouf
  • 18.7k
  • 7
  • 51
  • 66

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -I ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

Assuming you're using OpenSSH you can configure your ~/.ssh/config file for each, then you won't have to specify a user either, you can create your own name:

host host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test

then when you do ssh host1 it will do that automatically, or, since you will use host1 as other users too you can do

host test-host1
    User testuser
    IdentityFile ~/.ssh/id_rsa-test
    Hostname host1

then do ssh test-host1

and you can do the same for each host you want.

Any host that isn't matched by an entry in your ssh_config(5) file will use the default behavior--or use the defaults that are specified in ssh_config at the global setting, i.e., not inside a host block

ssh_config doesn't support matching on usernames, but you could write a shell script to detect that for you. Here's a fragile one that assumes your username/host is always the first argument and will break if it is not:

ssh() {
    if [[ "$1" =~ ^testuser@ ]]; then
        command ssh -I ~/.ssh/id_rsa-test "$@"
    else
        command ssh "$@"
    fi
}
Source Link
Eric Renouf
  • 18.7k
  • 7
  • 51
  • 66
Loading