Access my server through SSH with the domain (with Cloudflare)

I have this server (44.44.44.44, for instance) running a webserver. I have routed pollnote.com to the server to access my webserver. Everything works fine.

To access the server, I added my Public Key to .ssh/authorized_keys so I can do ssh [email protected] to log in without problems.

The issue comes when I try it like this: ssh [email protected]. The terminal just displays nothing, and it waits for me until I decide to abort the command.

What do I need to do to access the server using the domain name as reference?

UPDATE

I should have mentioned, I am accessing the server through CloudFlare. Maybe it is relevant..?

data

➜  ~  dig pollnote.com

; <<>> DiG 9.9.5-9ubuntu0.1-Ubuntu <<>> mydomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56675
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;pollnote.com.          IN  A

;; ANSWER SECTION:
pollnote.com.       299 IN  A   104.27.165.70
pollnote.com.       299 IN  A   104.27.164.70

;; Query time: 54 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Thu Jul 30 19:12:38 CEST 2015
;; MSG SIZE  rcvd: 73

➜  ~  ssh -vvv [email protected]
OpenSSH_6.7p1 Ubuntu-5ubuntu1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to pollnote.com [104.27.165.70] port 22.

Solution 1:

When you connect by IP address the SSH connection goes directly to your server but if you use the domain name it goes through Cloudflare defenses. My suggestion would be to either use direct.pollnote.com (I think CloudFlare creates it automaticaly but people often remove it) or add your own alias like ssh.pollnote.com and disable CloudFlare protection on it.

Solution 2:

You can use something like is outlined here.

If I try to SSH to the domain, our IPs will show & that will cause issues (the same would go for something like ftp).

Solution 3:

dtoubelis's answer definitely solves this problem.

Friendly amendment, consider using something other than ssh.yourserver.com so that potential attackers have a harder time identifying your host's IP address.

For example, secret-circus-monkey.yourserver.com.

See, e.g., A Proper Server Naming Scheme; notably the author's comment regarding attack vectors:

In the article, we mentioned that our naming scheme also allows you to prevent inadvertent information disclosure by publicly exposing only the short random hostname while resolving the functional names solely on the internal network.

Solution 4:

I wanted to add this as a comment to @dtoubelis's answer but the text formatting was too restrictive so I'm adding it as an answer instead.

In my case I added the following DNS Record to the "DNS" screen in Cloudflare:

Type     Name    Value                            TTL           Status
CNAME    ssh     is an alias of mywebsite.com     Automatic     Grey

I still couldn't get it to work until I realised you then have to change your ssh login command from:

ssh [email protected]

to

ssh [email protected].

I then added similar CNAME records for ftp and sftp so for example the ftp hostname in your ftp client changes from:

mywebsite.com

to

ftp.mywebsite.com.

I'm not sure if instead of a CNAME you can create an A record but it seems so according to Cloudflare.

Many thanks to @dtoubelis for the answer.