demotomohiro / remocolab

remocolab is a Python module to allow remote access to Google Colaboratory using SSH or TurboVNC.
MIT License
316 stars 229 forks source link

Unable to login as root #77

Closed lrushi closed 3 years ago

lrushi commented 3 years ago

I am unable to login as root. Normal user colab is working just fine but root user is not working by both using ssh keys and password.

I exactly followed the guide in readme.md and still unable to connect. This is what i ran in colab as mentioned after the ssh server creation.

!mkdir -p  /root/.ssh
with open("/root/.ssh/authorized_keys", 'w') as f:
  f.write("my public key")
!chmod 700 /root/.ssh
!chmod 600 /root/.ssh/authorized_keys

I used the root password as the input to the shell prompt. I even tried regular colab user password but it didnt work. Even ssh keys also didnt work. The following below is the output when i tried to connect with password.

$ ssh -o UserKnownHostsFile=/dev/null -o VisualHostKey=yes -p 15328 root@0.tcp.in.ngrok.io
The authenticity of host '[0.tcp.in.ngrok.io]:15328 ([3.6.115.64]:15328)' can't be established.
ECDSA key fingerprint is SHA256:7HzeV52D7cy7/8wO3MsGRCNWv6OWvfnV96Bnt1tQf6I.
+---[ECDSA 256]---+
|            ..   |
|           o o.  |
|          . o ...|
|       .     . .o|
|        S   . =o=|
|       o     =+B*|
|        o . E+OoB|
|         o ...=XX|
|          . o+.%^|
+----[SHA256]-----+
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[0.tcp.in.ngrok.io]:15328,[3.6.115.64]:15328' (ECDSA) to the list of known hosts.
root@0.tcp.in.ngrok.io's password:
Permission denied, please try again.
root@0.tcp.in.ngrok.io's password:
Permission denied, please try again.
root@0.tcp.in.ngrok.io's password:
root@0.tcp.in.ngrok.io: Permission denied (publickey,password).

If I made any mistake please tell me what to do to get root access else if not It may be a bug so please look into it as normal colab user is working just fine.

demotomohiro commented 3 years ago

After you login as colab user, you can use sudo to run a command that require root or su to become root. These command doesn't work for you?

lrushi commented 3 years ago

@demotomohiro it worked but I am using remocolab to use colab in vscode. Some times the I want to run jupyter notebooks as root. loginning in vscode and using jupyter from that wont give me root access inside jupyter notebooks in colab. So I tought having root access would be better for the ones who need it.

So if there is a chance to login as root it will be helpful.

demotomohiro commented 3 years ago

Please read this before enabling root login via ssh: https://unix.stackexchange.com/questions/82626/why-is-root-login-via-ssh-so-bad-that-everyone-advises-to-disable-it

I tested this code and it worked for me.

!mkdir /root/.ssh
with open("/root/.ssh/authorized_keys", 'w') as f:
  f.write("my public key")
!chmod 700 /root/.ssh
!chmod 600 /root/.ssh/authorized_keys

If you setup public key authentication correcly, you can login to ssh without using password. Did you setup public key in your ssh client correcly, and replaced "my public key" in above code to your public key? "my public key" string need to be replaced with content of your public key file including text that doesn't look random.

lrushi commented 3 years ago

I have no idea what I did wrong. The regular login as user "colab" is working just fine both password and ssh keys. But as soon as I try to login in as root it is giving me the error which I pasted above.
These are the things that I ran in order in jupyter notebook

  1. I generated the SSH keys using the command ssh-keygen -t ecdsa -b 521 as you mentioned.

  2. I stored my public key as a variable pubkey i.e pubkey = "content in the ecdsa.pub" and passed pubkey as argument to remocolab.setupSSHD() . This variable is my first cell.

  3. After that I ran the following commands as u mentioned in the readme that is

    !pip install git+https://github.com/demotomohiro/remocolab.git
    import remocolab
    remocolab.setupSSHD(public_key = pubkey, ngrok_region = "in", mount_gdrive_to = "drive")

    This is my second cell.

  4. After that cell I ran the following commands

    !mkdir /root/.ssh
    with open("/root/.ssh/authorized_keys", 'w') as f:
    f.write("my public key")
    !chmod 700 /root/.ssh
    !chmod 600 /root/.ssh/authorized_keys

    This is my third cell.

  5. I logged into ssh using this as colab and it worked fine with both ssh keys and password

ssh -o UserKnownHostsFile=/dev/null -o VisualHostKey=yes -p 10112 colab@0.tcp.in.ngrok.io 
  1. I removed colab from top command and replaced it with root and tried to ssh as root but failed

    ssh -o UserKnownHostsFile=/dev/null -o VisualHostKey=yes -p 10112 root@0.tcp.in.ngrok.io 
  2. It gave me the error as typed above in the previous comment. If I did any thing wrong tell me else I will just use ssh as user colab and I personally dont think I made any mistake.

demotomohiro commented 3 years ago

/root/.ssh/authorized_keys contains your public key? Did you edit sshd_conf?

I think you should report the issue to vscode so that you can do what you want to do without root login via ssh rather than trying to root login via ssh. Because this. There are people want to forbid root login via ssh. If vscode requires root login via ssh, they would never use it.

lrushi commented 3 years ago

I will use user colab and not root from now as u mentioned but its not just vscode even in terminal I have the same issue when I try to login as root. I don't think it is about vscode. May be its the region issue? idk. Any way thanks for your help.