4

To start with, I apologize if this is a painfully obvious/trivial issue, I'm still learning the ins and outs of linux/unix.

I work with a few servers that require access via ssh and private key to log into. So, the command is something like this:

ssh -i /path/to/key.pem [email protected]

I've created a bash script that let's me just use my own call, access, and just has a basic switch statement for the arguments that follow to control which server I log into. For example, access server1 would issue the appropriate ssh command to log into server1.

The Problem

The ssh call just hangs up and I'm left with an empty terminal that won't accept SIGINT (Ctrl + C) and I must quit the terminal and open it up again to even use it.

As far as I can tell, this might be a permissions thing for the private key. Its permissions are currently 600. Changing it to 644 gives me an error that the permissions are too open and exits the ssh attempt. Any advice?

2 Answers 2

6
  1. There is ssh_config, made for this, where you can specify your hosts aliases and keys and store it without creating such hara-kiri as bash scripts to do so. It is basically stored in your ~/.ssh/config in this format:

    Host host1
      Hostname 000.000.000.000
      User user
      IdentityFile /path/to/key.pem
    

    and then you can simply call

    ssh host1
    

    to get to 000.000.000.000

  2. If you really want to be effective and have even shorter shortcuts, bash alias is more suitable than the bash scripts.

    alias access="ssh -i /path/to/key.pem [email protected]"
    
  3. If you really want to use bash script, you need to force ssh to allocate you TTY on remote server using -tt option:

    ssh -tti /path/to/key.pem [email protected]
    

For more tips, you can browse through the manual page for ssh and ssh_config.

1
  • 1
    Well, if I didn't feel like I already knew too little about linux, I certainly feel that even more now. Thanks!
    – Andrew
    Nov 20, 2015 at 20:33
0

I generally make password auth available on servers (via console, assuming you are using virtualization), then ssh-copy-id soandso@server to get a key-based authentication going. Do note that in most cases you are using a public key (on your machine) to authenticate against a private key (on remote server).

The pub key standard permissions should be 644, however your private key should be 700 to the best of my knowledge. Are you sure your issue isn't the pub key permissions?

I would recommend checking two things: first, try the ssh connection string you did above, and add -v or -vvv as your option. This should give you a good idea where this is breaking at. Second, take a look at the sshd config file (/etc/ssh/sshd_config) on the server and make sure the connection protocol you are attempting to use is enabled. This could be as simple as making sure theses two lines are set to yes:

RSAAuthentication yes PubkeyAuthentication yes

Best of luck!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .