Have installed Anaconda Python on remote linux machine.
Used putty on local Windows to login to remote linux machine to remotely start the Ipython Notebook. It's started on port 8888.
remote_user#remote_host$ ipython notebook --no-browser --port=8888
Now I need to access this Notebook on local browser.
Have tried doing ssh tunnel.
C:\Users\windowsUser> ssh -N -f -L localhost:8888:localhost:8888 remote_user#remote_host
ssh: connect to host remote_host port 22: Bad file number
But not able to get it right. Getting the above error
Note: the user windowsUser does not exist on remote_host(linux). Remote user account is remote_user.
Where am i going wrong?
Plzz help
It appears you have a typo. In your ssh command you should not have "localhost" twice.
The corrected command is:
ssh -N -f -L 8888:localhost:8888 remote_user#remote_host
Because the syntax for the command is:
ssh -L <Local Port>:<Local Machine>:<Target Port> <Target Machine>
(see http://www.slashroot.in/ssh-port-forwarding-linux-configuration-and-examples)
Furthermore, you could instead modify your ssh config file (in ~/.ssh/config or /etc/ssh_config) to include port forwarding:
Host remote_host
Hostname PUT_REMOTE_IP_HERE
Port 22
User remote_user
LocalForward 8888 localhost:8888
I don't think window has a ssh cmd,
if local is a standard ssh client use
C:\Users\windowsUser> ssh -N -f -L 8888:localhost:8888 remote_user#remote_host
BTW
ipython notebook --ip=remote_host_ip
then you can access with http://remote_host_ip:8888/tree
Related
I have 4 Google cloud instances and I configured those as my hadoop cluster. I set static external IP to one of my instances to connect from my Linux machine (Windows subsystem for Linux). I tried to use sshuttle service to connect to that instance as VPN so that I can access another instances in my cluster through this VPN. sshuttle throwing error while connecting to my instance.
[ERROR]
sshuttle -r username#mystaticip 0.0.0.0/0 --ssh-cmd "ssh -i ~/.ssh/google_compute_engine"
[local sudo] Password:
client: Connected.
iptables v1.6.1: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
iptables v1.6.1: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
fatal: ['iptables', '-t', 'nat', '-nL'] returned 3
client: fatal: cleanup: ['sudo', '-p', '[local sudo] Password: ', 'PYTHONPATH=/usr/lib/python3/dist-packages', '--', '/usr/bin/python3', '/usr/bin/sshuttle', '--method', 'auto', '--firewall'] returned 99
As of now, Windows Subsystem for Linux (WSL) on Ubuntu does not support sshuttle. It seems that the Ubuntu inside the WSL does not fully support the iptables commands sshuttle is calling.
I have created a docker container to run my python program inside.
My program requires retrieving the known_host under my .ssh folder:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
ssh.connect(server, username=username, password=password)
I have mounted it into the docker container using:
docker run --name test_cntr --rm \
-v $SCRIPT_DIR:/home/ \
-v $DATA_DIR:/home/data \
-v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts \
-e PYTHONPATH=/home/sciprt_dir:/home/sciprt_dir/lib \
-e INDEX=0 \
dummy_image python /home/run.py
Found that my program can successfully get the known_hosts file sometimes, but sometimes not, below error is shown:
Exception is [Errno -2] Name or service not known
I didn't re-run the container during the run.py execution. Suppose the known_hosts mounted to the container at the beginning and run.py should be able to use it throughout whole running.
At the end I found that, one of the servers using for this program, did not register on the domain server, so that sometimes my program works when using server that is registered, and sometimes it does not work when the server is not registered.. Thanks all for help!
I want to run jupyter in docker container. I am not able to launch the jupyter notebook. When I copy paste the URL given in the terminal.. server cannot be reached. Will appreciate any ideas to try
You are forwarding port 8080 in the docker run call with -p 8080:8080. But you also need to forward port 8888 by adding -p 8888:8888. More specifically, you want to run:
docker -it -p 8080:8080 -p 8888:8888 jupyter/minimal-notebook
First thing is Jupyter nootbook runs on port 8888. If you want to access the notebook on a diff port on your host you should map it like this -p 80:8888.
If you don't mind using the defaults, you should use run the following command.
Run this command: docker run -p 8888:8888 jupyter/minimal-notebook. Then
replace the host name in the url given in terminal with localhost like this
http://localhost:8888/\?token\=<TOKEN>\&token\=<TOKEN>
This should work.
Note: If you map it to a diff port, you should replace it in the url you get in the terminal. Ex. http://localhost:80/\?token\=<TOKEN>\&token\=<TOKEN>
I'm using pxssh to establish an SSH connection to a server. To connection can be establish and I can run simple commands such as ls -l.
What I need now is to create iptable entries via that SSH connection.
I've tried the following
s = pxssh.pxssh()
print(ip)
if not s.login(ip, username, auth_password):
Log("SSH session failed on login")
Log(str(s))
else:
Log("SSH session login successful")
cmd = 'sudo iptables -I INPUT -p udp -m udp --dport 53 -j ACCEPT;'
s.sendline(cmd)
s.prompt()
print(s.before)
s.logout()
which runs without error, but when connection to the server, no iptable entry had been created!?
Try modifying your python script like this:
cmd = '/usr/bin/sudo /usr/sbin/iptables -I INPUT -p udp -m udp --dport 53 -j ACCEPT'
s.sendline(cmd)
You should change the sudo and iptables path if it's different on your OS
Also try printing the s.sendline(cmd) to see what actually is executed via the ptyhon script on the server, just to be sure that the correct iptables command is executed
I want to access notebook server remotely via a web browser, the following shows how did I setup my notebook server:
1.generate config file
$ jupyter-notebook --generate-config
$ cd ~/.jupyter
2.Use the following command to create the SSL certificate(Linux and Windows).
req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
3.edit the profile's configuration file, which is the jupyter_notebook_config.py the password has been generated..
c = get_config()
# You must give the path to the certificate file.
c.NotebookApp.certfile = u'/home/azureuser/.jupyter/mycert.pem'
# Create your own password as indicated above
c.NotebookApp.password = u'sha1:b86e933199ad:a02e9592e5 etc... '
# Network and browser details. We use a fixed port (9999) so it matches
# our Azure setup, where we've allowed :wqtraffic on that port
c.NotebookApp.ip = '*'
c.NotebookApp.port = 9999
c.NotebookApp.open_browser = False
4.start $ jupyter-notebook server
You should now be able to access your Jupyter Notebook at the address https://[PUBLIC-IP-ADDRESS]:9999.
Start notebook:
$ ~ jupyter-notebook
[I 16:46:58.627 NotebookApp] Serving notebooks from local directory: /home/user
[I 16:46:58.627 NotebookApp] 0 active kernels
[I 16:46:58.627 NotebookApp] The Jupyter Notebook is running at: https://SERVER_IP:9999/
[I 16:46:58.627 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
But, when I open my browser(at my home, the notebook server is in my lab) at https://MY_SERVER_IP:9999, the page can not be open. And Chrome-browser returns:
ERR_ADDRESS_UNREACHABLE
What should I do?
Those instructions you followed are a bit dated specifically:
Anaconda is at version 4.
Jupyter comes pre-installed with new Anaconda
Jupyter defaults to port "8888"
You should mention how to get to the modifications you note for the configuration. I ended up going into nano to do it.
You can't use "sudo" with conda.
If you want to install Ipython notebook from scratch on a VPS, and access it via ssh I wrote an updated tutorial here:
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-jupyter-notebook-to-run-ipython-on-ubuntu-16-04
After installing and running Ipython Notebook using command line on the server, you can connect to the notebook using SSH tunnelling with Putty (on windows) or the ssh -L command on Unix-like systems (ie Mac and Linux)
The corresponding port 9999 is block on the server, and the server is Centos7 and iptables is not available to open ports, so use firewall-cmd to active the port:
$ firewall-cmd --zone=public --add-port=9999/tcp --permanent
$ firewall-cmd --reload
If firewallD is not running, just start the service.