localhost:~ czh$ ssh root@192.168.16.111 root@192.168.16.111's password:123456 Last login: Mon Feb 19 22:57:28 2018 from 192.168.16.100
配置防火墙:
1
[czh@centos6 vhost]$ sudo vim /etc/sysconfig/iptables
防火墙开闭:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
关闭虚拟机防火墙:
关闭命令: service iptables stop
永久关闭防火墙:chkconfig iptables off
两个命令同时运行,运行完成后查看防火墙关闭状态 service iptables status
1 关闭防火墙-----sudo service iptables stop 2 启动防火墙-----sudo service iptables start 3 重启防火墙-----sudo service iptables restart 4 查看防火墙状态--sudo service iptables status 5 永久关闭防火墙--sudo chkconfig iptables off 6 永久关闭后启用--sudo chkconfig iptables on
# Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT
#ssh port -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#vsftpd -A INPUT -p TCP --dport 61001:62000 -j ACCEPT -A OUTPUT -p TCP --sport 61001:62000 -j ACCEPT
-A INPUT -p TCP --dport 20 -j ACCEPT -A OUTPUT -p TCP --sport 20 -j ACCEPT -A INPUT -p TCP --dport 21 -j ACCEPT -A OUTPUT -p TCP --sport 21 -j ACCEPT
#mysql port -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
#tomcat remote debug port -A INPUT -p tcp -m tcp --dport 5005 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
重启防火墙:
1 2 3
[czh@centos6 vsftpd]$ sudo service iptables restart [sudo] password for czh: iptables: Applying firewall rules: [ OK ]
修改selinux:解决外网是可以访问上去了,可是发现没法返回目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
[czh@centos6 ftpfile]$ getsebool -a | grep ftp allow_ftpd_anon_write --> off allow_ftpd_full_access --> off allow_ftpd_use_cifs --> off allow_ftpd_use_nfs --> off ftp_home_dir --> off ftpd_connect_db --> off ftpd_use_fusefs --> off ftpd_use_passive_mode --> off httpd_enable_ftp_server --> off tftp_anon_write --> off tftp_use_cifs --> off tftp_use_nfs --> off [czh@centos6 ftpfile]$ setsebool -P allow_ftpd_full_access on Cannot set persistent booleans without managed policy. [czh@centos6 ftpfile]$ sudo setsebool -P allow_ftpd_full_access on [sudo] password for czh: [czh@centos6 ftpfile]$ sudo setsebool -P ftp_home_dir on [czh@centos6 ftpfile]$
防止匿名账户不能创建更改文件情况:
1 2 3
[czh@centos6 ftpfile]$ sudo vim /etc/selinux/config [czh@centos6 ftpfile]$ sudo setenforce 0 [czh@centos6 ftpfile]$ sudo service vsftpd restart
[czh@centos6 ftpfile]$ cd ~/developer/apache-tomcat-7.0.73/bin/ [czh@centos6 bin]$ ./startup.sh Using CATALINA_BASE: /home/czh/developer/apache-tomcat-7.0.73 Using CATALINA_HOME: /home/czh/developer/apache-tomcat-7.0.73 Using CATALINA_TMPDIR: /home/czh/developer/apache-tomcat-7.0.73/temp Using JRE_HOME: /usr/java/jdk1.7.0_80 Using CLASSPATH: /home/czh/developer/apache-tomcat-7.0.73/bin/bootstrap.jar:/home/czh/developer/apache-tomcat-7.0.73/bin/tomcat-juli.jar Tomcat started.
[czh@centos6 .ssh]$ ssh-keygen -t rsa -C "czh55@qq.com" Generating public/private rsa key pair. Enter file in which to save the key (/home/czh/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/czh/.ssh/id_rsa. Your public key has been saved in /home/czh/.ssh/id_rsa.pub. The key fingerprint is: 31:a1:b2:53:f8:da:40:05:60:15:60:d8:34:80:f5:c9 czh55@qq.com The key's randomart image is: +--[ RSA 2048]----+ |o*O++o. . | |oo.+ + . . | | E o o | | . = o | | + . S | | = | | . . | | | | | +-----------------+ [czh@centos6 .ssh]$ ssh-add ~/.ssh/id_rsa Identity added: /home/czh/.ssh/id_rsa (/home/czh/.ssh/id_rsa) [czh@centos6 .ssh]$ ll 总用量 8 -rw-------. 1 czh czh 1675 2月 21 00:11 id_rsa -rw-r--r--. 1 czh czh 394 2月 21 00:11 id_rsa.pub [czh@centos6 .ssh]$ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAx3IlwhJZNJXM4BeYPmdrdURMAZxd/2k6ePmcJnddS20R4Y13N4dsqkGiK2qaQIJmHv07O5/hiaUztq/HHFj9bhNCxvNVjFZq6k6IWfNYj6eUuSc/5wtdsoGRkVKjxxW/Cxw21SmwM7d8ax7/4QTJTLM2/EcOBtA+v6QZ1++2Khj0slhhxIixxyccxV0NG0SvLo3oKG4alfUU43Pt7+a1BL7jUXdnUzr5GTpF6Z2XgBjn3NkSjQZb5EYcI14UzwldR7H6JBIqQySG1VAEIitasJFLEMRKVyhnyOdR+p6jkX7WNYerP/BB9OtqUg7OSFlkk7OXM1D49i+83pr00YDiFQ== czh55@qq.com
[czh@centos6 vhost]$ sudo service mysqld start Initializing MySQL database: WARNING: The host ‘centos6.8-linux.shared’ could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! Installing MySQL system tables… 180220 18:41:23 [Warning] ‘–default-character-set’ is deprecated and will be removed in a future release. Please use ‘–character-set-server’ instead. OK Filling help tables… 180220 18:41:23 [Warning] ‘–default-character-set’ is deprecated and will be removed in a future release. Please use ‘–character-set-server’ instead. OK
To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:
Alternatively you can run: /usr/bin/mysql_secure_installation
which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]
1 2
第一次登陆,并删除匿名用户:
[czh@centos6 vhost]$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> select user,host from mysql.user; +——+————————+ | user | host | +——+————————+ | root | 127.0.0.1 | | root | centos6.8-linux.shared | | mmal | localhost | | root | localhost | +——+————————+ 4 rows in set (0.00 sec)
mysql>
1 2 3 4
创建数据库: 注:这里的数据库名用``,而不是使用单引号’‘
mysql> create database mmall default character set utf8 collate utf8_general_ci; Query OK, 1 row affected (0.00 sec)
1 2 3
查看和设置权限: [mysql权限](bear://x-callback-url/open-note?id=4FE6BA17-41ED-45D6-9335-A994D160CBFF-331-0004AB35243310F3)这里要看这片文章才会明白为啥设计了权限之后,我们的select * from mysql.user \G;之后结果仍然为N
mysql> select * from mysql.user \G; *** 1. row *** Host: localhost User: root Password: Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 *** 2. row *** Host: centos6.8-linux.shared User: root Password: Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 *** 3. row *** Host: 127.0.0.1 User: root Password: Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 *** 4. row *** Host: localhost User: mmal Password: *B24D58108523CB417C6988470B0FD4141D7FBAF6 Select_priv: N Insert_priv: N Update_priv: N Delete_priv: N Create_priv: N Drop_priv: N Reload_priv: N Shutdown_priv: N Process_priv: N File_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Show_db_priv: N Super_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Execute_priv: N Repl_slave_priv: N Repl_client_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Create_user_priv: N Event_priv: N Trigger_priv: N ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 4 rows in set (0.00 sec)
ERROR: No query specified
1 2
mysql> grant all privileges on mmall.* to mmall@’%’ identified by ‘mmall’ with grant option; Query OK, 0 rows affected (0.00 sec)
1 2 3
注:此时的结果不变
设置root用户密码:
mysql> set password for root@localhost=password(‘root’); Query OK, 0 rows affected (0.00 sec)
mysql> set password for 127.0.0.1@localhost=password(‘root’); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘127.0.0.1@localhost=password(‘root’)’ at line 1 mysql> set password for root@127.0.0.1=password(‘root’); Query OK, 0 rows affected (0.00 sec)
[czh@centos6 vhost]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8
1 2
重启mysql
[czh@centos6 vhost]$ sudo service mysqld restart [sudo] password for czh: Stopping mysqld: [ OK ] Starting mysqld: [ OK ]
1 2 3 4
navicat连接mysql: [MYSQL ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.10.210’ (111) 解决方法 - 当年亦如是 - 博客园](https://www.cnblogs.com/zihanxing/p/7049244.html)
[czh@localhost bin]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.