Stránka 3 z 3

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 09 říj 2023 21:42
od rhsCZ
Odstraň # to značí že to je poznámka
Takže to bude vypadat

Kód: Vybrat vše

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

Port 8000
Port 8888
Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
KbdInteractiveAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

Pak dej

Kód: Vybrat vše

systemctl restart sshd.service

A vyzkoušej to ssh na portech 8000 a 8888

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 10 říj 2023 20:21
od d-pozz
Když se zkusím připojit, píše:

Permission denied (publickey).

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 11 říj 2023 06:42
od rhsCZ
Dobře, připojení k serveru funguje. Tak to můžeš dát do původního stavu
viz.

Kód: Vybrat vše

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
KbdInteractiveAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

a restartovat ssh.

Kód: Vybrat vše

systemctl restart sshd.service

můžeš dát podklady jak jsi to instaloval? já bych si to sám zkusil nainstalovat, vyzkoušel a případně bych dal vědět.

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 11 říj 2023 11:20
od d-pozz
Dobře, co myslíš, tu aplikaci?

Zde je postup:

Kód: Vybrat vše

https://github.com/OpenBMB/ChatDev


Potom jsem zadal týmu úkol, ať vyvine flask appku a vytvořili ji. Vidím ji normálně ve složce při připojení SFTP, a když ji commandem chci spustit, tak se spustí (main.py), ale veřejně není přístupná (v prohlížeči internetu).

Dodatečně přidáno po 16 minutách 37 vteřinách:
Podle mě tam asi dělá problém ten caddy. U každého updage/upgrade nebo instalace novější verze Pythonu 3.9, píše:

Kód: Vybrat vše

N: Ignoring file 'caddy-stable.list.old' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension
N: Ignoring file 'caddy.list.old' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension
E: Unable to locate package caddy


tak tedy jdu takto:

Kód: Vybrat vše

sudo rm /etc/apt/sources.list.d/caddy-stable.list.old
sudo rm /etc/apt/sources.list.d/caddy.list.old


načež odstranit nejde, píše:

Kód: Vybrat vše

 sudo rm /etc/apt/sources.list.d/caddy-stable.list.old
sudo rm /etc/apt/sources.list.d/caddy.list.old
rm: cannot remove '/etc/apt/sources.list.d/caddy-stable.list.old': No such file or directory
rm: cannot remove '/etc/apt/sources.list.d/caddy.list.old': No such file or directory


Tak jako divný. Asi vymazat a zapálit celou VM a udělat novou.

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 11 říj 2023 16:05
od rhsCZ
Caddy by měl být web server nejspíš nutný pro tu flask app.
zkus pustit

Kód: Vybrat vše

sudo rm -rf /etc/apt/sources.list.d/*

pak zkus

Kód: Vybrat vše

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

když bude úspěch bez errorů tak tu appku vyzkoušej. pokud ne, tak sem hoď chyby co to hlásí.

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 13 říj 2023 12:24
od d-pozz
Prošlo bez erroru, appka se spustí, ale když kliknu na adresu s portem, tak se otevře v prohlížečí, ale "nelze načíst stránku".

Kód: Vybrat vše

 * Serving Flask app 'web_app'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8000
 * Running on http://soukroma-ip:8000

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 13 říj 2023 13:19
od rhsCZ

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 13 říj 2023 18:43
od d-pozz
Nefunguje:/

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 13 říj 2023 19:01
od rhsCZ
Pošleš mi prosím do sz veřejnou ip? já sám bych to zkusil otevřít. a nech puštěnou tu aplikaci. a prosím podívej se jestli neexistuje nějaká složka logs s logama ve složce s tou aplikací případně jestli by nešel pustit nějak ten debug mode.
můžeš to pustit takto na pozadí a zavřít ssh.

Kód: Vybrat vše

python3 main.py &

a vypnout pak můžeš

Kód: Vybrat vše

killall python3

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 13 říj 2023 21:49
od d-pozz
posláno

Re: Přístup k flask app (spuštěné na VM - linux) z internetu (prohlížeče)

Napsal: 20 říj 2023 16:41
od d-pozz
Takhle tam mám například Ingress a Egress rules. Flask appka je zapnutá a běží na 127.0.0.1:5000, ale když to zadám do Google Chrome, tak píše

Kód: Vybrat vše

127.0.0.1 refused to connect


A když dám to samé, ale s veřejnou IP, tak se dlouho načítá a pak napíše v prohlížeči:

Kód: Vybrat vše

.... took too long to connect


Mně to přijde, jako by to chtělo nějaký gateway, aby se prostě někdo mohl veřejně připojit k tomu serveru z veřejného internetu, protože takto to nejde. Načítá se, načítá se, ale nenačte se.

Dodatečně přidáno po 2 hodinách 42 minutách 28 vteřinách:
stejné téma se řešilo např. tady, ale taky nevyřešeno: https://stackoverflow.com/questions/723 ... g-the-page