Domanda

My issue is that everytime I have to login to a given account on a linux server (there are many) I have to go pull a text file not I have to look at the username and ip.

Example: "ssh some_user@xxx.xxx.xxx.x -pxxxxx"

I want to make my life a little easier by creating a shortcut, e.g. "ssh some_user"...

I searched and could not find an answer, likely not using the right terminology.

Thanks!

È stato utile?

Soluzione

You can use the ssh client configuration file (.ssh/config). If you have to type ssh -p 1234 mylogin@my.server.with.a.long.name.com, you can populate your config file with

host server
    hostname my.server.with.a.long.name.com
    user mylogin
    port 1234

Then you can simply type ssh server and it will have the same effect. You can have as many entries in your .ssh/config file as you want and even use wildcards (*)

If you are using a recent version of bash, you can furthermore make use of the command_not_found_handle function:

command_not_found_handle () {
    if grep "host $1" ~/.ssh/config &>/dev/null; then
        ssh $@
    else
       printf "Sorry: Command not found: $1\n"
       return 127
    fi
}

Then you can connect simply with

server

Altri suggerimenti

I dont know if I understood your problem correct, but a proper ssh config file make life muuuch easier. No IP, no domain, no password, not even a username.

See the man page: http://linux.die.net/man/5/ssh_config

I like things like ssh vm, or scp vm:... no more scp blablubb@192.168.226.xy:...+ passphrase.

Also see ssh-keygen and ssh-copy-id for asymmetric key exchange. Will get you rid of typing passwords.

Generally I recommend to read a ssh tutorial.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top